14Mar2011
JavaScript Submit();
As some of you know, submitting a form via JavaScript is often essential. Especially for JavaScript rich applications. I was currently debugging some code at work and ran into a bug I just could not wrap my head around. It was currently getting all POST data, and resetting it in hidden input fields so the user can fill out more parts of a larger form.
Anyways, one of the submit buttons were actually named “submit” which got posted on part of the form. This can cause an error when submitting since it tries to access the variable based on it’s name.
<script type="text/javascript"> function mySubmit() { alert(document.googleSearch.submit.value); // "BlaineSch Rocks!" document.googleSearch.submit(); // Error } </script>
<form method="get" name="googleSearch" id="googleSearch" action="http://www.google.com/search"> <input type="hidden" name="submit" value="BlaineSch Rocks!" id="submit" /> <input type="text" name="q" value="" /> <a href="javascript:mySubmit();">Submit</a> </form>
This could be avoided by having an array of fields you want to actually use, or simply inserting them into a database/session.

Discussion
No responses to "JavaScript Submit();"
There are no comments yet, add one below.
Leave a Comment