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

Example analysis of the difference between js form submission and submit submission_javascript skills

WBOY
Release: 2016-05-16 15:26:20
Original
1209 people have browsed it

The example of this article analyzes the difference between js form submission and submit submission. Share it with everyone for your reference, the details are as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<script>
function test()
{
  document.getElementById("myform").submit();  
  alert(11);
}
</script>
<form name="myfrom" id="myform" method="get" action="b.php">
<input type="text" name="pwd" value="" />
<input type="submit" name="sub" value="111" />
<input type="button" name="btn" value="btn" onclick="test()" />
</form>
</body>
</html>

Copy after login

Note: When submitting a form through get method, you cannot use url to pass the value in action, but you can pass it like this in post

The difference between js submission and submit button submission:

1. When js submits a form, it will not bring the value of the submit button (because it has not been clicked) in all browsers

2. Enter and press Enter to submit. The w3c browser will bring the value of the submit button, but ie6 will not.

Solution:

Add a hidden field, use this to judge, no matter which method is used to submit, it will have value

Bind the submit event on the submit button:

That is:
The value of submit will be included, and the onsubmit status cannot be detected if submitted using js
w3c: Submit once
ie6: Submit in two steps, first submit js in form

Solution:

If the button is submit, use the onsubmit event to detect

If the button is a button, the submit event will be triggered after passing the detection

Be sure not to use js to submit the form, and then use onsubmit to detect it

Simply use js to submit the form, alert, block the submission of the form under ff, and other browsing

I hope this article will be helpful to everyone in JavaScript programming.

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!