Monday 27 June 2011

Post a form using JavaScript


We normally post a form with Submit button but we can also post a form using JavaScript.
We can use image or simple hyperlink to post a form using this method.

Just  Create a simple HTML page using this code and change the form action and view in browser.


<html>
<head>
<title>
Programing Tutorial by Anurag
</title>
<script language="javascript">
function formsubmit()
{
 document.formName.submit();
}
</script>
</head>
<form name="formName" method="get" action="page2.htm">
Name:<input type="text" name="name">
<a href="#" onclick="formsubmit();">Click Here to submit</a>
</form>
<body>
</body>
</html>

When you test it in your browser yow will see that your form will be posted and posted data will be seen in url of the page2.htm.

No comments:

Post a Comment