Get Around Form submit() Mapping
Posted on | November 3, 2008 | 1 Comment
If you’ve had to use javascript to submit a form, you may have used the forms submit() method. You may also experienced difficulty, such as a “submit is not a function” error. It has to deal with mapping and I’ve got a very simple solution.
The Setup:
Just so you know, this is done with MooTools 1.2, but if you know javascript, you can build it from scratch.
1 2 3 4 5 6 7 | <form id="response_form" action="response.html" method="get">
<fieldset>
<legend>Test</legend>
Grab the response.
<input type="submit" name="submit" value="submit" />
</fieldset>
</form> |
1 2 3 4 5 6 7 | <script type="text/javascript"> var form = $('response_form'); form.getElement('input[type=submit]').addEvent('click', function(e){ e.stop(); form.submit(); }); </script> |
The Test:
Copy the code into a test html file. Open Firebug (you DO have Firebug and FireFox, don’t you?) and display the console. Click on the submit button and there should be an error.
The Solution:
Very simple now. Change the name to anything besides submit and you’ve fixed the mapping issue.
1 | <input type="submit" name="submit_btn" value="submit" /> |
This one took me a while to find, but I was glad when I did. I hope this is helpful.
Comments
One Response to “Get Around Form submit() Mapping”
Leave a Reply
October 12th, 2009 @ 9:19 pm
this is very handy, yet very helpful.
input button name change. that simple.
thanks