Form. submit () cannot submit form Cause Analysis, form onsubmit

Source: Internet
Author: User

Form. submit () cannot submit form Cause Analysis, form onsubmit

Directly Add the following code:

Copy codeThe Code is as follows:
<Div id = "register">
<H4> Member registration <Div class = "formdiv">
<Form method = "post" action = "register. php? Action = register "name =" register "id =" registerForm ">
<Dl>
<Dt> enter the following content carefully </dt>
<Dd class = "hasspan">
Username: <input type = "text" name = "username">
</Dd>
<Dd class = "hasspan">
Password: <input type = "password" name = "pwd">
</Dd>
<Dd class = "hasspan">
Confirm password: <input type = "password" name = "pwdagain">
</Dd>
<Dd id = "tximg">

<Input type = "hidden" name = "touxiang" value = ">
<Label id = "imgsrclabel"> m01.gif </label>
</Dd>
<Dd style = "margin-right: 120px;">
Verification code: <input type = "text" name = "code">
<Span>

<A href = "# code" id = "change"> change one </a>
</Span>
</Dd>
<Dd class = "btns">
<Input type = "button" name = "submit" id = "submit" value = "register">
<Input type = "button" name = "quit" id = "quit" value = "quit">
</Dd>
</Dl>
</Form>
</Div>
</Div>

The form data is submitted to this page. The following is js processing.

Copy codeThe Code is as follows:
/* Open a registry ticket */
Function formDeal ()
{
Var btnSubmit = document. getElementById ('submit ');
Var formId = document. getElementById ('registerform ');
BtnSubmit. onclick = function ()
{
// The submit () method of the form cannot submit the form.
FormId. submit ();
}

}

If the form is submitted, a message is displayed on this page.

Copy codeThe Code is as follows:
If (! Empty ($ _ GET ['action']) & $ _ GET ['action'] = 'register ')
{
Echo 'you submitted data ';
Exit ();
}

After testing for a long time, I didn't see any prompts. I thought the code was wrong or the method was wrong. I checked carefully and confirmed that there was no error in the Results official document.

FormId. submit () cannot be submitted, so we have to change the type of btnSubmit to submit.

Copy codeThe Code is as follows:
This. type = "submit"

I checked the information online for two reasons:

1. The form cannot contain the name = "submit" label.

2. The form cannot contain "enctype =" multipart/form-data"

After testing, these two points are ridiculous and have not solved my problem (maybe my problem environment is different)

Later, I thought the Forum friends suggested that I change the Registration button ID to a name without submit. After correction, the form is submitted normally and the prompt message appears.

Conclusion: do not set the button id to submit. Otherwise, confusion may occur. As a result, the submit () method of the form cannot submit the form. When naming an ID, it is recommended that the name be unique with the existing api to avoid unnecessary troubles.


Formsubmit cannot be submitted

I'm not familiar with the vecolity template, but I need to submit a method, post or get in the background. Check if flag is true.
 
Why does documentformsubmit () in js fail to submit button values?

Declare another <input type = "hidden" name = "XX"/> to save the value so that the server can obtain it.
When submitting a form, write an onsubmit event to combine values.
When you submit the form, the browser will not splice the button to name and value to submit. If you want to submit the form, it will only trigger it by writing JS.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.