Debbie-Leigh Posted February 15, 2007 Share Posted February 15, 2007 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 Quote Link to comment Share on other sites More sharing options...
fenway Posted February 15, 2007 Share Posted February 15, 2007 Like an alert(1) doesn't fire? Quote Link to comment Share on other sites More sharing options...
Debbie-Leigh Posted February 17, 2007 Author Share Posted February 17, 2007 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 Quote Link to comment Share on other sites More sharing options...
fenway Posted February 18, 2007 Share Posted February 18, 2007 I've never actually run into this before... I'll see what I can find out. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.