Reputation: 6752
Why cant I use onChange in ie? And is there a solution for this?
HTML:
<select id="auto_doors" style="display:none;" name="auto_doors" onchange="updateField(this.value, 'auto_fuel', 5, 6, this.parentNode.id), resetBelow(4,'auto'), show('auto_fuel')">
</select>
Function:
if (jQuery.browser.msie) { setTimeout(DoSomething, 0); } else { DoSomething(); }
function updateField(str, id, prevvalue, value, vehicletype)
{
if (str=="")
{
document.getElementById(id).innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(id).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","inc/form_rest.php?q="+str+"&prevvalue="+prevvalue+"&value="+value+"&vehicletype="+vehicletype,true);
xmlhttp.send();
}
Upvotes: 0
Views: 536
Reputation: 1418
You can use jQuery to fix this problem code will be something like this:
$('#auto_doors').change(function() {
alert('Handler for .change() called.');
});
Upvotes: 1
Reputation: 2318
Try binding the on on change event to the auto_doors element like this instead:
$("#auto_doors").change(function(){
updateField(this.value, 'auto_fuel', 5, 6, this.parentNode.id), resetBelow(4,'auto'), show('auto_fuel');
});
Upvotes: 1
Reputation: 324840
Three observations that may help:
new XMLHttpRequest()
is sufficient.onreadystatechange
after calling .open()
. In some browsers (probaby just IE) calling .open()
counts as a "new request" and clears the readystatechange handler.this.value
on a <select>
. Instead, you should use this.options[this.selectedIndex].value
.Upvotes: 0