Why the following doesn’t work on IE8 while it works on the all other browsers.
$(function () {
//add binding to dropdowns
$("#PersonsId").change(function () {
$('option:selected', this).attr('selected', true).siblings().removeAttr('selected');
//set value on hidden text field
if ($(this)[0].selectedIndex > 0) {
$(this).parent().next().val($(this).find("option:selected").text());
}
else {
$(this).parent().next().val("");
}
});
});
Maybe this isn’t the best solution so i’m asking how would you change this?
The line
is not needed because when you select the option the rest of the options is unselected by default. For setting the value to hidden field use the following code
$(“input[type=’hidden’]”).val($(this).val());