0

enter image description here

       var ArrivalCity = (data.aircraftView[0].arcftSchedList[0].tripArrivalCity);
       $('select[title="Select the Destination"]').val(ArrivalCity);

       var ArrivalCity1 = (data.aircraftView[1].arcftSchedList[0].tripArrivalCity);
       $('select[title="Select the Destination"]').val(ArrivalCity1);

I am trying to populate the choice field from jquery on the SharePoint list. I am able to get the values but it is not getting stored in my choice field defined. I have multiple values coming into the arrival city and departure city, so I am getting those values from rest api. I am not sure why they are not getting populated in my choice field. I have attached a screenshot of the selector. Can anyone please help me with this?

4
  • Check out stackoverflow.com/questions/317095/… – Jason James Aug 30 '18 at 16:21
  • is there anything I need to change it this line of code? $('select[title="Select the Origin"]').val(DepartureCity); – Prashanth Edige Aug 30 '18 at 17:24
  • First of all check for the selector. Are you getting the desired select element using $('select[title="Select the Origin"]').val(DepartureCity)?? – Ganesh Sanap Aug 30 '18 at 18:48
  • Yes Select the origin is the choice field in sharepoint list new item. And the selector is select for the choice field. I am not sure what should I use to populate the values in the choice field. – Prashanth Edige Aug 30 '18 at 18:52
1

Append options to select element.

$('select[title="Select the Destination"]').append($('<option></option>').val("value1").html("text1"));
            $('select[title="Select the Destination"]').append($('<option></option>').val("value2").html("text2"));

Update:

var Options = [{ "Value": "Value1", "Text": "Text1" },
        { "Value": "Value2", "Text": "Text2" },
        {"Value": "Value3","Text":"Text3"}]
        $(function () {
            $.each(Options, function () {
                $('select[title="Select the Destination"]').append($('<option></option>').val(this.Value).html(this.Text));
            })
            //$('select[title="Select the Destination"]').append($('<option></option>').val("value1").html("text1"));
            //$('select[title="Select the Destination"]').append($('<option></option>').val("value2").html("text2"));
        })
3
  • I am basically getting the values from the json data and storing them in a variable and then appending to the option. How can i do that ? – Prashanth Edige Aug 31 '18 at 12:42
  • Check my update. – Lee_MSFT Sep 3 '18 at 1:24
  • How can I populate values based on two changes say for example I select date and one more column, based on the selection of date and one more column other fields should populate. – Prashanth Edige Sep 10 '18 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.