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

JS submission form example analysis_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:26:251498browse

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.

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