Home Web Front-end JS Tutorial Error causes and solutions when form.submit() cannot submit the form_javascript skills

Error causes and solutions when form.submit() cannot submit the form_javascript skills

May 16, 2016 pm 04:34 PM
form submit

Go directly to the code:

<div id="register">

<h4>会员注册</h4>

<div class="formdiv">

<form method="post" action="register.php&#63;action=register" name="register" id="registerForm">

<dl>

<dt>请认真填写以下内容</dt>

<dd class="hasspan">

用户名:<input type="text" name="username">

</dd>

<dd class="hasspan">

密码:<input type="password" name="pwd">

</dd>

<dd class="hasspan">

确认密码:<input type="password" name="pwdagain">

</dd>

<dd id="tximg">

<img src="img/face/m01.gif" alt="选择头像" id="faceimg">

<input type="hidden" name="touxiang" value="">

<label id="imgsrclabel">m01.gif</label>

</dd>

<dd style="margin-right:120px;">

验证码:<input type="text" name="code">

<span>

<img src="code.php" alt="code" id="code" name="code">

<a href="#code" id="change">换一张</a>

</span>

</dd>

<dd class="btns">

<input type="button" name="submit" id="submit" value="注册">

<input type="button" name="quit" id="quit" value="退出">

</dd>

</dl>

</form>

</div>

</div>

表单数据提交到本页面,下面是js处理

/*注册表单提交*/

function formDeal()

{

var btnSubmit = document.getElementById('submit');

var formId = document.getElementById('registerForm');

btnSubmit.onclick = function()

{

//表单的submit()方法不能提交表单

formId.submit();

}


}

如果表单提交,在本页面有一段提示信息

if(!empty($_GET['action']) && $_GET['action'] == 'register')

{

echo '你提交了数据';

exit();

}
Copy after login

The result is that after testing for a long time, I did not see the prompt message. I thought that the code was wrong or the method was written wrong. I checked carefully and checked the official results document to confirm that there was no error.

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

this.type="submit"

After checking the information online, the reasons can be summed up in two points:

1. The form cannot have the tag name="submit"

2. "enctype="multipart/form-data"" cannot be missing from the form

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

Later, I thought some forum friends suggested that I change the ID of the registration button to a new name instead of submitting. After the correction, the form is submitted normally and the prompt message appears.

Final summary: Do not set the id of the button to submit, otherwise it may cause confusion and cause the submit() method of the form to fail to submit the form. When naming the ID, it is best not to duplicate the name with the existing API to avoid unnecessary annoyance.

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

BinaryX is renamed FORM again, and the FOUR it gives to the community is about to soar? BinaryX is renamed FORM again, and the FOUR it gives to the community is about to soar? Mar 04, 2025 pm 12:00 PM

BinaryX's token name change: from BNX to FOUR, and then to FORM, the deep meaning behind strategic adjustments BinaryX recently changed the token symbol from $FOUR to $FORM, which has attracted widespread attention from the industry. This is not the first time BinaryX has changed its name, and its token symbol has undergone a transition from BNX to FOUR. This article will explore in-depth the strategic intentions behind this series of name change. 1. Token name change process and strategic considerations BinaryX initially launched the $BNX token based on the BNB chain in 2021 to support its Play-to-Earn (P2E) gaming ecosystem. In early 2024, in order to optimize the economic model, BinaryX divided $BNX and gradually expanded to GameF

How to use v-on:submit to listen to form submission events in Vue How to use v-on:submit to listen to form submission events in Vue Jun 11, 2023 am 10:48 AM

Vue is a popular JavaScript framework that helps developers build interactive front-end applications. Forms are very common interface elements in Vue applications. When the user enters data into the form and submits it, we may need to listen for the form submission event. This article will introduce how to use the v-on:submit directive in Vue to listen for form submission events. First, defining form elements in Vue requires using Vue's data binding syntax. Let's say we have a form,

Can there be multiple forms in html5? Can there be multiple forms in html5? Aug 01, 2022 pm 05:28 PM

There can be multiple forms in html5. The rules allow multiple form tags to be used in the same HTML page. However, in order to prevent the backend from not recognizing it when submitting, you need to add different IDs or classes to the form. The syntax is "<from action="url" id=" id value 1">Form element</from><from action="url" id="id value 2">Form element</from>.....".

What is the tag that defines the form in html5 What is the tag that defines the form in html5 Jul 26, 2022 pm 04:26 PM

The tag defining a form in HTML5 is "<form>". The form tag is used to create an HTML form (form field) for user input to collect and transfer user information. All content in the form will be submitted to the server; the syntax "<form action="Submit Address" method="Submit Method " name="form name">form control</form>". A form can contain one or more form elements, such as input, select, and textarea.

Comprehensively organize elements related to form forms! Comprehensively organize elements related to form forms! Aug 05, 2022 am 11:45 AM

This article gives you a detailed summary of the knowledge points related to form elements in HTML. I hope it will be helpful to you!

What should I do if the form cannot be submitted to php? What should I do if the form cannot be submitted to php? Dec 01, 2022 am 09:08 AM

Solution to form form cannot be submitted to PHP: 1. Open the corresponding code file; 2. Modify the "onload="javascript:document.form1.submit();" statement; 3. Change the name of submit.

php记录搜索引擎蜘蛛爬行记录代码 php记录搜索引擎蜘蛛爬行记录代码 Jun 13, 2016 am 10:08 AM

php记录搜索引擎蜘蛛爬行记录代码。php教程记录搜索引擎蜘蛛爬行记录代码 center form action=setup.php method=post table align=center tr td服务器:/tdtdinput value=localhost name=server //td /tr tr td用

为什么小弟我在php上写的这个代码,在浏览器上什么都不显示 为什么小弟我在php上写的这个代码,在浏览器上什么都不显示 Jun 13, 2016 am 10:24 AM

为什么我在php上写的这个代码,在浏览器上什么都不显示啊

See all articles