The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

HTML/JavaScript question... by kahuana 2003-03-18 20:40:24
I'd like to make text change colour whenever a form field is "invalid".

Is there a way to do this in Mozilla?

Here's what i've got so far:

function trim(n)
{
return n.replace(/^\s*(.*?)\s*$/,'$1');
}

function validPhoneNumber(n)
{
  return ((0==trim(n).search(
    '[2-9][0-9]{2}[ \-\.\/][2-9][0-9]{2}[ \-\.][0-9]{4}'+
    '|[2-9][0-9]{2}[ \-\.][0-9]{4}'))
           ?1
           :0);
}
var validHomePhone = 0;
function validatePhone(frm,elem)
{
var obj = eval('document.' + frm + '.'+ elem);
var lbl = eval('document.all.lbl' + elem);
lbl.color = validPhoneNumber(obj.value) ? "black" : "red";
}
A typical input box might be:
< font id="lblfoo" color="black">< b>Home Phone:< /b>< /font>
< input type="text" name="foo" id="foo"
onchange="validatePhone('myform','HomePhone')" >
Naturally, the document.all.~ doesn't work under anything but IE.
Can this be done without resorting to 'graphics'?
TIA

[ Reply ]
  Have you tried DOM? by Naruki2003-03-18 20:47:15
    "Not gunna go there, wouldn't be prudent, by Adiplomat2003-03-18 21:20:49
  Styles are the best way. by Khaar2003-03-18 21:49:49
    Thanks a bunch! by kahuana2003-03-18 22:38:42
    Oh, and TVM! by kahuana2003-03-18 22:39:17

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)