Instant validation problem
- From: Gavin <GJPeacock@xxxxxxxxx>
- Date: Thu, 7 Feb 2008 16:34:06 -0800 (PST)
Hi Guys, i hope one of you are able to help with my problem. I'm a
novice when it comes to Javascript, but i'm trying to write a script
that performs instant validation on a signup page (ajax style!)
Basically, when a user starts entering text in a field an image of a
tick or cross appears deppending on if the input is valid.
The code i have so far is being run on a keyup event trigger. I would
be really grateful if someone could advise me what i am doing wrong,
and how to fix the script. Firebug is not proving to be very
useful...
function validate_form(source)
{
if (source == "fname")
{
if (( document.form1.fname.value.length =>2 ) &&
( document.form1.fname.value.length =<30 ))
{
document.images[fnameimg].src= "imgs/style/good.png";
valid = true;
} else {
document.images[fnameimg].src= "imgs/style/error.png";
valid = false;
}
}
if (source == "sname")
{
if (( document.form1.sname.value.length =>2 ) &&
( document.form1.sname.value.length =<30 ))
{
document.images[snameimg].src= "imgs/style/good.png";
valid = true;
} else {
document.images[snameimg].src= "imgs/style/error.png";
valid = false;
}
}
if (source == "email")
{
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+
$/.test(form1.email.value))
{
document.images[emailimg].src= "imgs/style/good.png";
valid = true;
} else {
document.images[emailimg].src= "imgs/style/error.png";
valid = false;
}
}
if (source == "email_conf")
{
if ( document.form1.email.value ==
document.form1.email_conf.value )
{
document.images[email_confimg].src= "imgs/style/good.png";
valid = true;
} else {
document.images[email_confimg].src= "imgs/style/error.png";
valid = false;
}
}
if (source == "pswd")
{
if ( document.form1.pswd.value.length => 5 )
{
document.images[pswdimg].src= "imgs/style/good.png";
valid = true;
} else {
document.images[pswdimg].src= "imgs/style/error.png";
valid = false;
}
}
if (source == "conf_pswd")
{
if ( document.form1.pswd.value ==
document.form1.conf_pswd.value )
{
document.images[conf_pswdimg].src= "imgs/style/good.png";
valid = true;
} else {
document.images[conf_pswdimg].src= "imgs/style/error.png";
valid = false;
}
}
if (source == "submitdata")
{
return valid;
}
}
I am trying to load this as an external file if that makes any
difference.
Many thanks,
Gavin
.
- Follow-Ups:
- Re: Instant validation problem
- From: McKirahan
- Re: Instant validation problem
- Prev by Date: FAQ Topic - Internationalization and Multinationalization in javascript. (2008-02-08)
- Next by Date: Re: What is wrong with my JSON string???
- Previous by thread: FAQ Topic - Internationalization and Multinationalization in javascript. (2008-02-08)
- Next by thread: Re: Instant validation problem
- Index(es):
Relevant Pages
|