Go Back   CodingForums.com > :: Client side development > JavaScript programming > Post a JavaScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 9 votes, 2.44 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-01-2004, 02:25 AM   PM User | #1
josses
New Coder

 
Join Date: Jan 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
josses is an unknown quantity at this point
Internet Explorer this is a working form valadition script

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.
eg:
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!

enjoy!

<script>
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()
alert(erroralert)
return false
}
}
</script>
josses is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:31 PM.


Advertisement
Log in to turn off these ads.