Home > Article > Web Front-end > JS submission form example analysis_javascript skills
The example in this article describes how to submit a form using JS. Share it with everyone for your reference, the details are as follows:
1. Automatically submit the form when javascript page is added:
Form:
<form method="post" id="myform" action="a.php"> <input type="submit" value="提交表单"> </form>
javascript code:
<script type="text/javascript"> function validate(){ document.getElementByIdx_x('myform').submit(); } window.load=validate(); </script>
Note: When submitting a form using Javascript, it is best not to use id="submit" or name="submit" for the elements in the form, For example:
2830d5732caa5af9a79d7a1a0a5d6871 or ff7f89cdfb53b82ebfadb3a74949ad61 In this caseJS may not be compatible with various browsers and will cause JS to report an error .
2. Hyperlink Submission Form
Form:
<form method="post" id="myform" action="a.php"> <input type="test" value="name"/> </form> <a href="javascript:validate()">提交</a>
javascript code:
<script type="text/javascript"> function validate(){ document.getElementByIdx_x('myform').submit(); } </script>
Using javascript is actually really convenient to do certain things!
I hope this article will be helpful to everyone in JavaScript programming.