How to Submit a Form Using JavaScript

Form can be submitted by submit button. If you are looking to submit form with explicit function, JavaScript can help you in submitting form with submit function.

Before using submit function you need a form in webpage.

This javascript submit function can call by any event of html tag. This can be onclick of anchor tag, button tag.

Submit function

document.formName.submit();

Can call from any attribute

<a href=”javascript:goSubmit()” >Submit form </a >

Or can be

<input type=”button” name=”btn” value=”Submit” onClick=”goSubmit()”>

Full example code

<html>
<head>
<title>Submit form using javascript</title>
<script>
function goSubmit()
{
  document.frm.submit();
}
</script>
</head>

<body>
<form name="frm">
 <a href="javascript:goSubmit()">Submit form </a>
 <br>
 <input type="button" name="btn" value="Submit" onClick="goSubmit()">
</form>
</body>
</html>
Bookmark  

 

One Response to “How to Submit a Form Using JavaScript”

  1. shawngo says:

    Promote better JavaScript documentation! For more information on submitting forms with JavaScript, go to the Mozilla Developer Center https://developer.mozilla.org/en/DOM/form.submit

Leave a Reply

Security Code:

 

  Random Post