Archive for JavaScript

How to Submit a Form Using JavaScript

Monday, April 13th, 2009

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>