Home > Web Front-end > JS Tutorial > JS submission form example analysis_javascript skills

JS submission form example analysis_javascript skills

WBOY
Release: 2016-05-16 15:26:25
Original
1552 people have browsed it

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>

Copy after login

javascript code:

<script type="text/javascript">
function validate(){
 document.getElementByIdx_x('myform').submit();
}
window.load=validate();
</script>

Copy after login

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:
or 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>

Copy after login

javascript code:

<script type="text/javascript">
function validate(){
 document.getElementByIdx_x('myform').submit();
}
</script>

Copy after login

Using javascript is actually really convenient to do certain things!

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

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