Hi there!
basically i have built a form and validated the input using regular expressions. When the user enters an invalid entry (onChange) an alert box pops. This works fine. However alert boxes can create problems for visually impaired users who use screen magnification. So what i am trying to do is create an additional error msg at the side of the input box.
similar to the example shown here:
http://www.xs4all.nl/~sbpoley/webmatters/formval.html
I attempted many ways of doing this and i cannot seem to get it to work. I have run the code through a javascript varifier so there should not be a typing/spelling errors.
Here is the function:-
- Code: Select all
function ValidatePhoneNum()
{
var PhoneNum = document.Form.shipPhoneNumber.value;
var n = document.getElementById("contactNum");
var msg=n.nextSibling.nodeValue; //this is the part which seems to be the issue
var re = /^\d{4}\s*\d{7}|\d{5}\s*\d{6}$/;
if (!re.test(PhoneNum))
{
alert("Please re-enter Phone number");
document.Form.shipPhoneNumber.focus();//this does not work either
msg = "Please re-enter Phone number"; //this will replace "required"
return false;
} else {return true;}
}
And here is the
html:-
- Code: Select all
<td>Contact Telephone Number</td>
<td id=contactNum><input type="text" name="shipPhoneNumber" maxlength="30"
onChange="return ValidatePhoneNum()"/>Required</td>
If anyone can sugguest a reason why this does not work i would greatly appreciate it.
Thanks!