Home > Web Front-end > JS Tutorial > Analysis of the difference between JavaScript submission form and submit submission

Analysis of the difference between JavaScript submission form and submit submission

黄舟
Release: 2017-11-18 15:13:39
Original
2800 people have browsed it

In our previous two articles, we introduced to you JavaScript Several methods to implement submission forms, as well as methods to verify JavaScript submission forms, and there is a certain submit submission in the submission form , then today we will give you an analysis of the difference between JavaScript submission form and submit submission!

<!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: Action cannot be used when submitting the form using get method urlpass value, post can pass like this

The difference between js submission and submit button submission:

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

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

Solution: Add a hidden domain, use this to judge, no matter which method is used to submit, there will be a value

Submit button is bound to submit event :

That is:

<input type="submit" name="btn" value="btn" onclick="test()" />
Copy after login

will bring the value of submit, and the onsubmit status cannot be detected even if submitted with js

w3c: Submit once

ie6: Submit in two times, first submit js in the form

Solution:

Detect if the button is submit When using onsubmit event detection

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, ff blocks the submission of the form, while other browsing

Summary:

According to the detailed introduction in this article, I believe that my friends are familiar with JavaScript What is the difference between submitting a form and submitting? You can decide which one to choose according to your own needs!

Related recommendations:

Sharing three methods of JavaScript submission form verification


Several ways to submit a form using JavaScript


##javascript processing form example (javascript submission form)

The above is the detailed content of Analysis of the difference between JavaScript submission form and submit submission. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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