1

Here I am creating dynamic table inside jQuery by using AJAX call. In this table I am creating select box. But I have to provide the dynamic values to that select box, so I am using the id of that select box and appending the data inside it.

But I am not able to solve the issue.

Qualification.js

 function switchOption() {
    var  selectedValue= $("#companyClass").val();
    $.ajax({
        type: "GET",
        url: "getClass",
        data:'classId='+selectedValue,
        success: function(data){
            var tablebody = $('<tbody>');
            var tablerow = "";
            $(data.qualAttributes).each(function(index){
                tablerow = $('<tr>')
                    .append($('<td>').append($('<input>').attr({type :'checkbox'}).attr('class','checkBoxSize').attr({value : ''+$(this)[0].qualId}).attr('id','attributeList').attr('name','attributeList')))
                    .append($('<td>').append($(this)[0].qualAttrName+''))
                    .append($('<td>').append($('<select>').attr('class','form-control').attr('id','operatorList').attr('name','operatorList')))
                    .append($('<td>').append($('<input>').attr({type :'text'}).attr('class','form-control').attr('id','attributeValue').attr('name','attributeValue')))
                    .append($('<td>').append($('<input>').attr({type :'hidden'}).attr('class','form-control').attr('id','attributeValueHidden').attr('name','attributeValueHidden').attr('value',$(this)[0].qualId)))
                $(tablebody).append(tablerow);

            });

            $(data.operatorList).each(function(i,value){
                $('#operatorList1').append($('<option>',
                     {
                        value: value.dropdownId,
                        text : value.dropdownValue,
                    }));
                });

Portion of Qualification.jsp

  <div class="form-group">
    <label class="label-bg col-xs-12">Class <span class="red">*</span></label>
    <div class="col-xs-12">
     <form:select id="companyClass" class="form-control" path="companyClass" onchange="switchOption();">
        <form:option value="Select" />
        <form:options items="${classList}" itemValue="id" itemLabel="dropdownValue"/>
    </form:select>              
    </div>
  </div>

No values are in list box

Note: there are no errors in the log. If I print value.dropdownId in console it is giving correct value.

Is it possible that while defining select in jQuery, can I append the values by using like this?

$(data.operatorList).each(function(i,value){
                $('#operatorList1').append($('<option>',
                     {
                        value: value.dropdownId,
                        text : value.dropdownValue,
                    }));
                });
halfer
  • 19,824
  • 17
  • 99
  • 186
Diwakar Bhatt
  • 495
  • 2
  • 11
  • 24
  • You can choose some option from here http://stackoverflow.com/questions/170986/what-is-the-best-way-to-add-options-to-a-select-from-an-array-with-jquery – Olena Horal Sep 27 '16 at 13:19
  • @OlenaHoral i have tried lot of things, but none seems to be wok here. if i see the value of **value: value.dropdownId**, **value.dropdownValue** in console log it showing correct values.But it is not making it as select box options – Diwakar Bhatt Sep 28 '16 at 04:37
  • any leads would be appreciated. – Diwakar Bhatt Oct 07 '16 at 09:44

0 Answers0