See some example below to learn how to submit a form using javaScript.
Simple code:
<form name="myform" action="handle-data.php">
Search:
<input type='text' name='query'>
<a href="javascript: submitform()">Search</a>
</form>
<SCRIPT language="JavaScript">
function submitform()
{
document.myform.submit();
}
</SCRIPT>
JavaScript Form Submit Example 2
The code:
First create a file named "submitjs.js" (just example you can rename it whatever you want).
write this code to this js file:
<SCRIPT LANGUAGE="JavaScript">
var myformValidator = new Validator("myform");
myformValidator.addValidation("query","req","Please enter the value for query");
</SCRIPT>
<SCRIPT language="JavaScript">
function submitform()
{
if(document.myform.onsubmit())
{//this check triggers the validations
document.myform.submit();
}
}
</SCRIPT>
And then you can include this script to your html or php page using this code:
<SCRIPT src="submitjs.js" language="JavaScript"></SCRIPT>
Be sure that you write the right path. The src address must be the address path where you put submitjs.js file.
Okey, after it is finished, now you can add the code below on your html page :
<form name="myform" action="handle-data.php">
Search: <input type='text' name='query'>
<A href="javascript: submitform()">Search</A>
</form>
note:
The name of the submit form must be the same with name on the javascript. In the example case above we use "myform" just find it and you will undestand.


