You are here: irt.org | FAQ | JavaScript | Form | Q1472 [ previous next ]
Try:
<script language="JavaScript"><!-- function validate(theForm) { errorField = -1; for (i=0,n=theForm.elements.length;i<n;i++) { if (theForm.elements[i].value == '') { errorField = i; break; } } if (errorField !=-1) { alert('Please correct field number ' errorField+1); theForm.elements[i].focus(); return false; } return true; } //--></script> <form onSubmit="return validate(this)"> ... </form>