help with validation

This is a discussion on "help with validation" within the JavaScript Forum section. This forum, and the thread "help with validation are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jul 26th, 2007, 14:58
New Member
Join Date: Jul 2007
Location: england
Age: 29
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
help with validation

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!

Last edited by karinne; Jul 26th, 2007 at 15:00. Reason: Please use [ code ]...[ /code ] tags when displaying code!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jul 26th, 2007, 20:20
Junior Member
Join Date: Jul 2007
Location: West Midlands
Age: 26
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help with validation

well the other alternative is to place a blank DIV placeholder next to the fields, then when you use the alert box just do an
document.getElementById("divid").innerHTML = "Error message here";

there we go.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jul 26th, 2007, 22:58
Rob's Avatar
Rob Rob is online now
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,182
Blog Entries: 7
Thanks: 27
Thanked 21 Times in 18 Posts
Re: help with validation

I would say that innerHTML is the way to go.

For streamlining your code (for validation and Search engines) to avoid blank elements, you could pick upon the field itself and use various methods to add a child or sibling element to target innerHTML.

Something to think about anyway!
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
form validation, getelementbyid, nextsibling, nodevalue

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with validation snappy Web Page Design 4 Mar 27th, 2008 18:33
w3c validation cocoonfx Web Page Design 8 Jul 21st, 2007 13:55
CSS validation VanessaJW Web Page Design 17 May 24th, 2007 19:59
CSE for validation nextgen Scripts and Online Services 3 Jan 30th, 2007 03:41
Validation help Powderhound Web Page Design 13 Nov 4th, 2006 20:53


All times are GMT. The time now is 21:16.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42