Jump to content

Onchange not working in IE


Debbie-Leigh

Recommended Posts

Hi,

 

I have a select field that has an onchange attribute that fires an ajax script to fill out another field. It's working perfectly in every browser except IE, but I just cannot figure out why it's not being triggered in IE.

 

My code is:

The HTML:

<select name="CountryId" id="CountryId" size="1" title="Choose a country" tabindex="1" onchange="funChangeField(document.frmOrder,'Action','country');funSubmitForm(document.frmOrder);">

The js file (it's triggered first on page load to change the onchange attribute, if HTTPRequest is available, then when the field changes to fire off the HTTP Request and lastly to process the response to fill out and show the second field):

function funCountryChg(objResp, strUrl, objField, strMsgField) {
    // Process a country field when it changes
var strHdgFld, strDataFld, objHdgFld, objDataFld;

if  (objResp == 1) {
    if  (window.XMLHttpRequest || window.ActiveXObject) {
        objField.setAttribute("onchange", "funCountryChg(2, '" + strUrl + "?Id=' + this.value, document.getElementById('" + strMsgField + "'));");
    }
} else if (objResp == 2) {
	if  (objField != null && objField != '') {
		objField.innerHTML = 'Please wait ...';
		objField.parentNode.className = objField.parentNode.className.replace(/hide/i, 'show');
	}
	funHTTPReq(strUrl);
} else {
	strHdgFld  = objResp.getElementsByTagName('hdgname')[0].firstChild.data;
	strDataFld = objResp.getElementsByTagName('dataname')[0].firstChild.data;
	objHdgFld  = document.getElementById(strHdgFld);
	objDataFld = document.getElementById(strDataFld);

	if  (objResp.getElementsByTagName('showrow')[0].firstChild.data == 1) {
		objHdgFld.innerHTML  = objResp.getElementsByTagName('hdgcontent')[0].firstChild.data;
		objDataFld.innerHTML = objResp.getElementsByTagName('datacontent')[0].firstChild.data;
		objHdgFld.parentNode.className = objHdgFld.parentNode.className.replace(/hide/i, 'show');
	} else {
		objHdgFld.innerHTML  = '';
		objDataFld.innerHTML = '';
		objHdgFld.parentNode.className = objHdgFld.parentNode.className.replace(/show/i, 'hide');
	}
    }
    
    return true;
}

 

IE is definitely setting the onchange attribute, but it just refuses to fire it when the selection changes.

 

Can anyone tell me what I have to do differently in IE to get it to fire the onchange event?

 

Thanks.

 

Debbie

 

Link to comment
Share on other sites

Hi,

 

Well, I've tested this to death and tried a whole bunch of things. What I eventually found is the only way to get a javascript set onchange to fire in ie is to set the onchange attribute like this:

 

objField.onchange = funCountryChg;

 

It seems that ie treats event attributes totally differently than every other browser - as straight functions rather than allowing a function to be set as a string.

 

It doesn't even seem to like this:

 

objField.onchange = function(){funCountryChg()};

 

which I've seen quoted in many places as something you should be able to do.

 

My problem is that I need to pass a few parameters to the function at the time it is invoked, but ie doesn't seem to allow this. So, does anyone know of a way to that I can pass the parameters to the function when it is triggered?

 

Thanks.

 

Debbie

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.