I have this form validation and I can't see why it won't check for the numeric property. Could someone take a look at it and let me know if I am missing something obvious?
<script language="JavaScript">
function verify(f){
var msg;
var empty_fields = "";
var errors = "";
for (var i = 0; i < f.length; i++) {
var e = f.elements;
if((e.type == "text") && e.required){
if((e.value == null) || (e.value == "")){
empty_fields += "\n " + e.name;
continue;
}
if((e.type == "text") && e.numeric){
var v = parseFloat(e.value);
if(isNaN(v)){
errors += "- The field " + e.name + " must be a number";
}
}
}
}
if (!empty_fields && !errors) return true;
msg = "_______________________________________________________________\n\n"
msg += " The form was not submitted because of the following error(s).\n";
msg += " Please correct these error(s) and re-submit.\n";
msg += "_______________________________________________________________\n\n"
if(empty_fields){
msg += "- The following required field(s) are empty:"
+ empty_fields + "\n";
if(errors) msg += "\n";
}
msg += errors;
alert(msg);
return false;
}
</script>
With the form prpoerties set like:
<form action="#SCRIPT_NAME#" method="post"
onSubmit="
this.AS_OF_DT.required = true;
this.ACTUAL_AM.numeric = true;
this.PLAN_AM.numeric = true;
this.CASH_AM.numeric = true;
return verify(this);
">
Thanks for any insight!
Va
<script language="JavaScript">
function verify(f){
var msg;
var empty_fields = "";
var errors = "";
for (var i = 0; i < f.length; i++) {
var e = f.elements;
if((e.type == "text") && e.required){
if((e.value == null) || (e.value == "")){
empty_fields += "\n " + e.name;
continue;
}
if((e.type == "text") && e.numeric){
var v = parseFloat(e.value);
if(isNaN(v)){
errors += "- The field " + e.name + " must be a number";
}
}
}
}
if (!empty_fields && !errors) return true;
msg = "_______________________________________________________________\n\n"
msg += " The form was not submitted because of the following error(s).\n";
msg += " Please correct these error(s) and re-submit.\n";
msg += "_______________________________________________________________\n\n"
if(empty_fields){
msg += "- The following required field(s) are empty:"
+ empty_fields + "\n";
if(errors) msg += "\n";
}
msg += errors;
alert(msg);
return false;
}
</script>
With the form prpoerties set like:
<form action="#SCRIPT_NAME#" method="post"
onSubmit="
this.AS_OF_DT.required = true;
this.ACTUAL_AM.numeric = true;
this.PLAN_AM.numeric = true;
this.CASH_AM.numeric = true;
return verify(this);
">
Thanks for any insight!
Va