Home >Web Front-end >JS Tutorial >The difference between js form submission 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>
Note: When submitting the form in the get method, the url value cannot be passed in the action. Post can be passed like this
The difference between js submission and submit button submission:
1. js will not be used when submitting the form The value of the submit button (because it has not been clicked) in all browsers
2. Press Enter to submit. The w3c browser will bring the value of the submit button, but ie6 will not.
Solution: Add a hidden domain, Use this to judge, no matter which method is used to submit, there will be a value
Bind the submit event on the submit button:
That is:f6fb0e64e89628f0f48891b7009ba687
will bring the value of submit, and the onsubmit status cannot be detected when submitting with js
w3c: Submit once
ie6: Submit in two times, submit js in the form first
Solution: If the button is submit, use onsubmit event detection when detecting
If the button is button, the submit event will be triggered after the detection is passed
Be sure not to use js to submit the form, and then use onsubmit to detect
Simply use js to submit the form, alert, ff will block the submission of the form, while other browsers
For more related articles on the difference between js form submission and submit submission, please pay attention to the PHP Chinese website!