| 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 |