This article mainly introduces form in JS. the reason why submit () cannot submit the form is incorrect. This article concludes that the button ID and name should not use submit. If you need it, you can refer to the following code:
The Code is as follows:
Member registration
The form data is submitted to this page. The following is js processing.
The 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.
The 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.
The 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.