Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Validating a form phone number but won't focus
Old 02-11-2010, 01:20 PM Validating a form phone number but won't focus
ericson3000's Avatar
Experienced Talker

Posts: 40
Name: Bob Davis
Location: Los Angeles, CA
Trades: 0
I'm trying to validate a phone number in a form. Everything works perfectly except that when someone puts in an incorrect number type, it will not focus after giving them the warning message. Any help would be wonderful.

Thanks

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>JS - Form Object - Validating a Phone Number</title>

<script type="text/javascript">
<!--
function validatePhone () {
if (document.signup.Phone.value.search (/\d{3}\-\d{3}\-\d{4}/) == -1) {
window.alert ("Please enter a valid phone number with the format 555-555-5555");
Phone.focus ();
return false;
}
else {
window.alert ("That is a correct format for a phone number");
}
}
//-->
</script>

</head>

<body>

<FORM NAME="signup" action="" METHOD="post"
onSubmit="return validatePhone ()">
<div style="text-align: left; padding-right: 28px">
Phone (xxx-xxx-xxxx):
<INPUT TYPE="text" NAME="Phone" VALUE="" SIZE=20><br><br>
</div>

<br>
<input type="submit" name="Submit">
</FORM>

</body>
ericson3000 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-11-2010, 04:54 PM Re: Validating a form phone number but won't focus
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Use a fully qualified reference to the element.

document.formname.elementname.focus()
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-11-2010, 09:51 PM Re: Validating a form phone number but won't focus
ericson3000's Avatar
Experienced Talker

Posts: 40
Name: Bob Davis
Location: Los Angeles, CA
Trades: 0
Thanks. I overlooked the obvious. I appreciate your help.
ericson3000 is offline
Reply With Quote
View Public Profile
 
Old 02-12-2010, 06:04 AM Re: Validating a form phone number but won't focus
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Originally Posted by ericson3000 View Post
Thanks. I overlooked the obvious.
We've all been there
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Validating a form phone number but won't focus
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20710 seconds with 12 queries