javascript - Html Dropdownlist built with jquery not working correctly -


i have following code dynamically build dropdown list on ie10 browser, depending on values retrieved database

function buildoption(container, namepreface, id, val, txt) {     var obj = $("<option />", { id : namepreface + id, value : val, text : txt});     $("#"+ container).append(obj);     return obj; } 

here html generated, copied f12, dom explorer

<li>     <span class="div120ralgn inlineblock">         <label for="costcenter">cost center:</label>     </span>     <span class="editor-field-allw220">         <select id="costcenter">             <option id="costcenter_0" value="0"> </option>             <option id="costcenter_3" value="3">all</option>         </select>     </span> </li> 

however first time click drop down arrow, empty box, isn't initialized.

enter image description here

when click on again, appears should

enter image description here

anybody have ideas going on , how fix it? problem consistent regardless of values , regardless number of options in list

this segment in in document ready function

$("#region").change(function (e) {     loadregionlocations(e.currenttarget); }); $("#location").change(function (e) {     loadlocationscostcenters(e.currenttarget); }); 

and these 2 methods called

function loadregionlocations(tar) {     $("#costcenter").empty();     $("#location").empty();     buildoption("location", "location_", 0, 0, ' ');     var selloc = searchargsforobjlst($(tar).val(), "regionid", "locationname", locationlst);     $.each(selloc, function (i, o) {         var c = buildoption("location", "location_", o.locationid, o.locationid, o.locationname);         c.data("regionid", o.regionid);     }); }   function loadlocationscostcenters(tar) {     $("#costcenter").empty();     buildoption("costcenter", "costcenter_", 0, 0, ' ');     var selcc = searchargsforobjlst($(tar).val(), "locationid", "costcentername", costcenterlst);     $.each(selcc, function (i, o) {         var c = buildoption("costcenter", "costcenter_", o.costcenterid, o.costcenterid, o.costcentername);         c.data("regionid", o.regionid);         c.data("locationid", o.locationid);     }); } 

i might have found solution above problem. @ least added code below , far been working.

$.fn.redraw = function () { $(this).each(function () {     var redraw = this.offsetheight; }); 

};

then in methods build options, added call method, so

    function loadlocationscostcenters(tar) {     $("#costcenter").empty();     buildoption("costcenter", "costcenter_", 0, 0, ' ');     var selcc = searchargsforobjlst($(tar).val(), "locationid", "costcentername", costcenterlst);     $.each(selcc, function (i, o) {         var c = buildoption("costcenter", "costcenter_", o.costcenterid, o.costcenterid, o.costcentername);         c.data("regionid", o.regionid);         c.data("locationid", o.locationid);     });     **$("#costcenter").redraw();** } 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -