I’m sending an Ajax call to the Database to get data to populate and create an existing Select Box.
After the select is created by using jQuery.html(), I am trying to pre-set the select box’s value. However, setting the value does not work all the time, and sometimes leaves the Select Box as the Default Option of “Select One” / -1 ONLY in IE8. Another thing to add is that I am making the Select Box viewable by using
$("#selectBox").css('display', 'block')
I am using jQuery.val().
I have tried $("#selectBox").val(id)
AND
$("#selectBox").find('option[value=' + id + ']').prop('selected', true);
BUT both present the same inconsistent results I have been running into.
you can try this, and you must make sure
idis the option’svalue attributeOr you must make sure the option have completely loaded before you use