When streaming out your html page from the server you could add the following to your fields to validate
1. In the header add your batch validation and a function to test if field is empty
2. Turn off form submission in the form tag so form is not submitted when the user presses the enter key
3. Add a button to form which will submit form if form is valid.
4. Adding the array to the form validation routine will allow you to show any and all missed fields.
Besides doing this it is also good to add field validation to the form instead of having the user wait until the form is submitted.
Since these can be overcome by hackers, it is still recommended that you add server side validation of the submitted form
- <HEAD>
-
-
<SCRIPT LANGUAGE="JavaScript">
-
<!--
-
// batch validation router on form submit
-
function validateForm(form) {
-
-
var aErrorList = new Array();
-
var chkList = "";
-
-
if (isNotEmpty(form.LastName)) {
-
aErrorList[aErrorList.length] = "Last Name"
-
}
-
-
if (isNotEmpty(form.FirstName)) {
-
aErrorList[aErrorList.length] = "First Name"
-
}
-
-
if (isNotEmpty(form.MrMrs)) {
-
aErrorList[aErrorList.length] = "Mr/Mrs"
-
}
-
-
if (aErrorList.length == 0){
-
return true;
-
}else{
-
for (var i = (aErrorList.length-1); i > -1 ; i--) {
-
if (i == 0){
-
chkList += aErrorList[i]
-
}else{
-
chkList += aErrorList[i]+","+"\n"
-
}
-
}
-
alert("Check the following: "+"\n"+chkList);
-
return false;
-
}
-
////end validate before submittal//////////
-
-
// validates that the field value string has one or more characters in it
-
function isNotEmpty(elem) {
-
var str = elem.value;
-
var re = /.+/;
-
if(!str.match(re) || str == " ") {
-
setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
-
return true;
-
} else {
-
return false;
-
}
-
}
-
//-->
-
</SCRIPT>
-
</HEAD>
-
-
<BODY >
-
-
<FORM
-
METHOD=POST
-
ACTION=""
-
NAME="f1"
-
onSubmit="return false"
-
>
-
-
<INPUT
-
TYPE="button"
-
onClick="if (validateForm(this.form)) {SaveSubmit(this.form)};"
-
name="MySubmit"
-
id="MySubmit"
-
value="Add"
-
/>
-
-
-
<INPUT
-
TYPE="text"
-
NAME="MrMrs"
-
id ="MrMrs"
-
/>
-
<INPUT
-
TYPE="text"
-
NAME="FirstName"
-
id ="FirstName"
-
/>
-
<INPUT
-
TYPE="text"
-
NAME="LastName"
-
id ="LastName"
-
/>
-
-
</FORM>
-
</BODY>
-