0

I want to populate all choices from SP(ChoiceField) into html select field...

This is my code:

function pageLoad() {
   var holidayList = clientContext.get_web().get_lists().getByTitle("Holidays");
   var protocolChoices = clientContext.castTo(holidayList.get_fields().getByInternalNameOrTitle("LirexHolidayProtocol"), SP.FieldChoice);
   var protocolOtherChoices = clientContext.castTo(holidayList.get_fields().getByInternalNameOrTitle("LirexHolidayProtocolOther"), SP.FieldChoice);

   clientContext.load(protocolChoices);
   clientContext.load(protocolOtherChoices);
   clientContext.executeQueryAsync(Function.createDelegate(this, successHandler), Function.createDelegate(this, errorHandler));

 //Fill DDls with protocols
   var choices = protocolChoices.get_choices();
   //alert("Choices: (" + choices.length + ") - " + choices.join(", "));

   var options = $("#noFunnyHoliday");
   $.each(choices, function () {
        options.append($("<option />").val(ChoiceNum).text(ChoiceValue));
   });
 }

1) What is the best way to fill select element with options(choices)...(Resolved)

2

I hope choices is already filled with text and Value.

$.each(choices , function(val, text) {
    $('#noFunnyHoliday').append( new Option(text,val) );
});

Thanks

  • I'll try, moment :) – Goshky Jan 16 '17 at 8:12

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.