I am trying to set value in "select" control using jQuery. It is observed that sometime it select value correctly and sometime it does not select value.
I have an xml document, below code pull xml value and set it to dropdown list (html select) This is my jQuery Bock.
var select = '#' + formname + ' select[binding="true"]'; //here select those dropdown whose binding property is true.
$(select).each(function (i) {
var bindName = $(this).attr("DataMember");
if (bindName != '') {
$xmlNode = $xml.find(bindName);
if ($xmlNode != null) {
var value = $xmlNode.text();
if (value == "0")
value = '';
$(this).val(value); //here actual value is set as per xml value
}
else
$(this).val('');
$(this).trigger("change");
$(this).trigger("chosen:updated");
}
});
Some time this code works some time it does not work. can anybody let me know what's the problem with this code.
No comments:
Post a Comment