Javascript Submit Form Not Working

Remember previously I was writing about how to do javascript to submit a form in html/jsp/php/asp. Well, surprisingly sometimes we discover things which are unexpected. For instance to submit a form without clicking the submit button but another link or button. Though something is wrong! The form doesn’t submit at all and there’s a javascript error too.

From the example above, imagine clicking the Send Data button to submit the form using javascript. (Well, the above is just an example and doesn’t do a thing though). The issue is what’s the matter? Here are the solutions.

Submit Form

If you have a submit button visible in your form, do rename your Submit button. For example

<input type="Submit" name="submit" value="submit">

should be renamed to something like

<input type="Submit" name="SendForm" value="submit">

Notice the difference? The name is change in the property of the input type. Now how do you explain this phenomena?

This is a naming issue. forms have a method called ‘submit’, but if you give a form element the name ‘submit’ then javascript will not be able to find the .submit method, causing your .submit function to never fire.

Finally all is well once again. If you’re still clueless as to how to create a form using buttons and submitting it via javascript, remember to visit this post to learn all about it.

Leave a Reply