Submitting a Form Using JavaScript
In order to submit a form using JavaScript, the form must have its name attribute set to a specific identifier.
Problem Encountered
A user has a form with the ID "theForm" and a DIV containing a submit button. When this button is clicked, the function "placeOrder()" is called, which changes the innerHTML of the DIV to "processing ..." and makes the submit button disappear.
The user's issue is that the code in the "placeOrder()" function to submit the form using the following line is not working:
document.theForm.submit()
Solution
To resolve this issue, set the name attribute of the form to "theForm". The modified code will look like this:
<form>
With this name attribute in place, the "placeOrder()" function's code will successfully submit the form:
function placeOrder() { // Change the inner HTML of the DIV // ... // Submit the form document.theForm.submit(); }
The above is the detailed content of Why Isn't My JavaScript Form Submission Working?. For more information, please follow other related articles on the PHP Chinese website!