We usually use input type submit for our forms to submit data to sime script.
What is the drawback of it ?
Answer : Soem of the fields may be empty but form is submitted.
How to check before submitting?
Answer:
for example you have form with one field and one submit button then you must set the form name in form tag as name=f1and, instead of setting type to submit set type of the button to button and grab the information in onclick event as following.
| CODE | <form name=f1 method=post> Enter your name <input type=text name=n> <input type=button value='GO' onclick="if(f1.n.value.length==0) alert('nme empty'); else f1.submit();" > </form>
|
now save the file as test.html, put this code in and response back if any error.
|