Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > HTML > HTML Code Clinic
|
HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2004, 12:48 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default Add Mask To Input Element

Hi.

I have a form that requires the user to enter in their phone number.
I'd like to place a mask of "(000)-0000 x99999" in the Input box but don't know how to do it. I could use the "Value" property but that's not quite what I'm looking for.

Any suggestions would be greatly appreciated.

Rita
 
Old July 20th, 2004, 02:19 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Why don't you just use multiple text boxes?

Snib

<><
 
Old July 20th, 2004, 02:32 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The design (not my design!) of the data file to which the text will be added has the extension together with the phone number. Even if I used 2 text boxes, I'd still like to use a mask for at least the phone number.
 
Old July 20th, 2004, 03:17 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I'm talking about something like this:

<form onsubmit='getPhoneNumber()' id='phone' [other attributes]>
(<input maxlength='3' type='text' id='t1'/>)-<input maxlength='3' type='text' id='t2'/>-<input maxlength='4' type='text' id='t3'/>
<input type='hidden' value='' id='phone_number' name='phone_number'/>
</form>

<script type='text/javascript'>
function getPhoneNumber()
{
 var p = document.forms.phone;
 p.phone_number.value = "(" + p.t1.value.toString() + ")-" + p.t2.value.toString() + "-" + p.t3.value.toString();
}
</script>

The form value 'phone_number' on the server side would then have the value of the three formatted textboxes.

HTH,

Snib

<><
 
Old July 20th, 2004, 03:33 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Interesting way of doing it! Better than what I had. Thanks.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Input Mask J.K.W.Y. Access 1 April 3rd, 2006 06:36 AM
equivalent of input mask in MSAccess deeraj VB.NET 1 March 22nd, 2005 12:05 AM
Input Mask MHarrison Excel VBA 0 December 2nd, 2003 12:11 PM
Creating an Input Mask in a text box in VB.NET ysu_computer_lab VS.NET 2002/2003 1 November 5th, 2003 02:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.