View Full Version : this is a working form valadition script

01-01-2004, 03:25 AM
A couple things that you might want to know is that this validatior doen't work with check boxes and radio buttons cause they already have a value

to work properly the fields must be seperated with a "," and no space
it doesn't matter so much it there is a space in the alertstr cause it is merly what you want it to say.
fldstr = 'field1,field2....'
alertstr = 'what i want to say if ppl do not fill in field1,what i want it to say if ppl don....'

also note that field names are case sensitive and that when calling this function you must have it in the <form> tag or it will be useless
callit using onSubmit="return mo_valadate('formwhatever','fld1,fld2,etc','say this, say that, etc')"

feel free to alterit and make it better
if you do improve on it email a version back to me if you want at josses@jodys.ca

another thing is i am not sure if it works with all browsers!


function mo_valadate(formname,fldstr,alertstr)
var fldarray = fldstr.split(",")
var alertarray = alertstr.split(",")
var valstr = ""
var errorstr = ""
var erroralert = "Plese fill in \n"
for (i=0;i<fldarray.length;i++){
valstr = eval("document."+formname+"."+fldarray[i]+".value==''")
if (valstr)
errorstr = errorstr + i + ","
if (errorstr.length > 0){
errorstr = errorstr.substring(0,errorstr.length-1)
errorarray = errorstr.split(",")
for (j=0;j<errorarray.length;j++){
erroralert = erroralert+"-"+alertarray[errorarray[j]]+"-"+ "\n"
erroralert = erroralert + "Thank You!"
erroralert = erroralert.toUpperCase()
return false