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/… Commented Aug 30, 2018 at 16:21
  • is there anything I need to change it this line of code? $('select[title="Select the Origin"]').val(DepartureCity); Commented Aug 30, 2018 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)?? Commented Aug 30, 2018 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. Commented Aug 30, 2018 at 18:52

1 Answer 1

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 ? Commented Aug 31, 2018 at 12:42
  • Check my update. Commented Sep 3, 2018 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. Commented Sep 10, 2018 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.