Home>

First, the form is automatically submitted when the javascript page is added:

form:

<form method="post" action="a.php">
<input type="submit" value="submit form">
</form>

javascript code:

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

Note:When submitting a form with javascript, it is best not to use id="submit" or name="submit" for the elements in the form, for example:

<input type="button" name="submit" />or<input type="button" />This way js may not be compatible with various browsers,Will cause js error.

Hyperlink submission form

form:

<form method="post" action="a.php">
<input type="test" value="name" />
</form>
<a href="javascript:validate ()">submit</a>

javascript code:

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

In fact, it is really convenient to do certain things with JavaScript!

  • Previous Detailed explanation of JavaScript based on object-oriented object creation (1)
  • Next Method for dynamically inserting CSS into JavaScript