Sinan Samet
Sinan Samet

Reputation: 6752

onchange in Internet Explorer

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

Answers (3)

Vuk Vasić
Vuk Vasić

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

meub
meub

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

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324840

Three observations that may help:

  1. There is no need to support IE6 and below anymore. new XMLHttpRequest() is sufficient.
  2. You should set onreadystatechange after calling .open(). In some browsers (probaby just IE) calling .open() counts as a "new request" and clears the readystatechange handler.
  3. Older versions of IE (IE7?) don't like this.value on a <select>. Instead, you should use this.options[this.selectedIndex].value.

Upvotes: 0

Related Questions