Home >Web Front-end >JS Tutorial >Why Isn't My JavaScript Form Submission Working?

Why Isn't My JavaScript Form Submission Working?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-12 15:22:02801browse

Why Isn't My JavaScript Form Submission Working?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn