18.10.06

onchange before onsubmit: no dice for IE

I'm sure this has been blogged endlessly and documented in msdn, but I just ran across this: On an HTML form, an input's onchange event won't get called when the input is changed and ENTER is hit. Apparently IE6 doesn't think it needs to.

This bug doesn't happen in Firefox, nor it happens if you're trying to use onblur. Try it:
<form onsubmit="alert('submit')">
<input onchange="alert('change')" onblur="alert('blur')" />
</form>
Update: I apologize for not posting a workaround. You can add an event which forces the input to blur (without having to explicitly define which input):
<form onsubmit="window.focus()">

3 comments:

Anonymous said...

Having a problem with this "null or not an object" JS error msg...here is the function that I am using:

function sendXML() {

var esrimapBlurb = "/esriconn/esri";
var theService = "?ServiceName=" + theServiceName;
var cVersion = "&CustomService=" + customService + "&ClientVersion=3.1";
var theForm = "&Form=True";
var actionURL = "http://" + hostName + esrimapBlurb + theService + cVersion + theForm;

var thePostFormOBJ = parent.PostFrame.document.forms[0];
alert(thePostFormOBJ);
//alert(actionURL);
thePostFormOBJ.action = actionURL;

thePostFormOBJ.ArcXMLRequest.value = theRequest;

thePostFormOBJ.JavaScriptFunction.value = "parent.MapFrame.processXML";

thePostFormOBJ.submit();
}


It error get thrown at the line where the var thePostFormOBJ is declared. I just don't understand why it ins't working...any help would be most appriciated...

Mark

φ said...

It's difficult to determine where errors come from just by looking at the code. I strongly suggest that you use a debugger like Venkman (for firefox - free) or if you have MS Office that you install the script debugger, which is excellent.

Another alternative, a bit more lighweight, is the Firebug plugin for Firefox. You should be testing each of the tokens in the line that is throwing the error, to know what is null. Is it because there's no PostFrame in the parent window? Is it because it hasn't loaded anything, so "document" is not available? etc.

Anonymous said...

Thanks for the quick response...this error is rather generic and tough to work thorugh for a newbie like myself...I will give your suggestions a shot. Thank you for your time.