Edinburgh Web Development

Ajax Firefox form submit problem

by Iain Wilson

5 February 2009

Here's a little problem we hit when writing a recent application using Ajax

We have a form that calls a Javascript Ajax function on submit which updates some of the POST values in the form based on the values of others. We were using an <input /> tag with a 'submit' attribute:

<input type="submit" value="Continue" onclick="delcalc();" />

This worked fine in IE but in Firefox (3.0.6) it aborted with the dreaded error message:

Error: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.statusText]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame ::

The Javascript worked great if it was assigned to an event elsewhere in the form, but as soon as it was assigned to the submit - ERROR!!. So it seemed that Firefox had a problem with updating form fields once the form moved into a 'submit ready' state.

The fix? After a few man years of testing and scratching around the web, it appears that we need to make the <input /> tag a 'button' type.

All done you might think, but of course if you use 'button' type of submit with an onclick event, most browsers these days won't fire the submit event (although they should, according to the standards). So you have to artificially do it using a hidden submit and an onclick event on an image, like this:

<input type="submit" name="hidSubmit" style="display:none"/>
<a href="#" onclick="delcalc(); document.cform.hidSubmit.click();return false;">
<img src="images/continue.gif" alt="" /></a>

That done, it will work with Firefox. Not sure, but it looks like Mozilla have acknowledged a bug that will be fixed in next release (couldn't quite understand the gobbledegook).

Liked this article? Please share it with your friends and colleagues.

comments powered by Disqus
Blot Design,
10 Colinton Road, Edinburgh, EH10 5DT
Terms, Cookies & Privacy