Submit a Form Using JavaScript

Posted under » JavaScript on 08 June 2009

The most popular way to submit a form is by using a submit button. Here you can use HTML to validate contents however, it does not work in Internet Explorer 9 or earlier.

 <form action="demo_form.php" method="post">
  <input type="text" name="name" required>
  <input type="submit" value="Submit">
</form>
<p>If you click submit, without filling out the text field, 
your browser will display an error message.

Next is by using an image button.

<form action="demo_form.php">
  First name: <input type="text" name="fname"><br>
  <input type="image" src="go.gif" alt="Submit and go" >
</form>

You can use input type button and then trigger your JavaScript.

<form>
  <input type="button" value="submit and go" onclick="puntion()">
</form>

<script type="text/javascript">
function puntion()
{
  document.forms["formname"].submit();
}
</script>

The button above activates a JavaScript that submits the form using the onlick command when it is clicked. If you want to use onSubmit, you place it on the <form> tag.

You can use a text link also via the getElementById.

<div id='create-user'>OPEN</div>

You can fill up form automatically with getElementById.

web security linux ubuntu GIT svn Raspberry apache mysql php drupal cake symfony javascript Ajax css