Home > Web Front-end > JS Tutorial > body text

Why Isn't My JavaScript Form Submission Working?

Patricia Arquette
Release: 2024-11-12 15:22:02
Original
731 people have browsed it

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()
Copy after login

Solution

To resolve this issue, set the name attribute of the form to "theForm". The modified code will look like this:

<form>
Copy after login

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();
}
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template