Masked input control (or simulation of)?

  • Thread starter Thread starter |{evin
  • Start date Start date
E

|{evin

I'm currently working on what has turned in to something much
larger that I wanted it to be. The upside is that I'm getting $$ to do
it... but anywho.

I currently have textboxes set up to capture phone numbers,
I've also got regular expression validation in place to force the
format of the number to be (xxx) xxx-xxxx. The problem is, the people
that are paying me don't want this. What they'd like to see is a magic
textbox that fills in the ( ) and - as you type, the other alternative
is 3 separate textboxes.. a 2 that are 3 digits wide and one that is
4.

Doing it with the 3 boxes sounds like the 'easier' way to go,
I can simply concatenate the 3 values together as I see fit before
sending them on to the database... however, if I use this method, they
want the focus to automagically move from box to box as the user
enters the digits.

I'm no javascript person, but assume this is what would be
needed to accomplish the result.

So, my question to all of you is... is there a drop-in masked
control that I can use to replace the textbox, or could someone give
me a hint on how to do the hocus focus thing?
 
Hi,

Here's some JavaScript you might use.

I put three textboxes on a form and added this in the HTML:
<script>
function Box1() {
if (Form1.TextBox1.value.length > 2)
Form1.TextBox2.focus();
}
function Box2() {
if (Form1.TextBox2.value.length > 2)
Form1.TextBox3.focus();
}
</script>

You might want to use RegisterClientScriptBlock instead of typing this
directly into the HTML.

Then I added this in the Page_Load
TextBox1.Attributes.Add("onkeypress", "Box1();")
TextBox2.Attributes.Add("onkeypress", "Box2();")

I hope this helps.

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.


--------------------
 
Hi,

Here's some JavaScript you might use.

I put three textboxes on a form and added this in the HTML:
<script>
function Box1() {
if (Form1.TextBox1.value.length > 2)
Form1.TextBox2.focus();
}
function Box2() {
if (Form1.TextBox2.value.length > 2)
Form1.TextBox3.focus();
}
</script>

You might want to use RegisterClientScriptBlock instead of typing this
directly into the HTML.

Then I added this in the Page_Load
TextBox1.Attributes.Add("onkeypress", "Box1();")
TextBox2.Attributes.Add("onkeypress", "Box2();")

I hope this helps.

Thank you, Mike
Microsoft, ASP.NET Support Professional

Very similar to something someone else suggested in another group,
altthough this looks a bit cleaner, I am not, however, familiar with
RegisterClientScriptBlock.
 
Hi,

For more on RegisterClientScriptBlock, please see
Injecting Client-Side Script from an ASP.NET Server Control
http://msdn.microsoft.com/library/en-us/dnaspp/html/aspnet-injectclientsides
c.asp

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.


--------------------
 
Hi,

For more on RegisterClientScriptBlock, please see
Injecting Client-Side Script from an ASP.NET Server Control
http://msdn.microsoft.com/library/en-us/dnaspp/html/aspnet-injectclientsides
c.asp

Thank you, Mike
Microsoft, ASP.NET Support Professional

I actually found this sometime after midnight last night. I went on to
develop a custom web control that encapsulated the 3 text boxes, the
movement from field to field, a routine that only allows numbers to be
entered into the textboxes, and a custom validator that forces all 10
digits to be entered.

Best of all, the textbox ID's and all of the javascript are generated
on the fly using RegisterClientScriptBlock.. I can place multiple
instances of the control on a web page and everything still gets
hooked up correctly! (although the page source gets a bit large...
there are 6 javascript functions generated for each control).

Thanks a TON!
 
Hi,

Here's some JavaScript you might use.

I put three textboxes on a form and added this in the HTML:
<script>
function Box1() {
if (Form1.TextBox1.value.length > 2)
Form1.TextBox2.focus();
}
function Box2() {
if (Form1.TextBox2.value.length > 2)
Form1.TextBox3.focus();
}
</script>

You might want to use RegisterClientScriptBlock instead of typing this
directly into the HTML.

Then I added this in the Page_Load
TextBox1.Attributes.Add("onkeypress", "Box1();")
TextBox2.Attributes.Add("onkeypress", "Box2();")

I hope this helps.

Thank you, Mike
Microsoft, ASP.NET Support Professional

Well, I thought I had it knocked out. :(

The code that automagically moves the cursor doesn't work with
NetScape 7.

if ( document.all("pcfax_TextBox1").value.length > 2 )
{
document.all("pcfax_TextBox2").focus();
}

I've tried replacing with something like

if ( document.getElementById("pcfax_TextBox1").value.length > 2 )
{
document.getElementByIdl("pcfax_TextBox2").focus();
}

But the browser complains that pcfax_TextBox2 has no properties. :(

Is there a cross-browser way to access elements by ID? I've noticed
that a lot of my custom validators do not fire correctly either
because of this same issue.
 
Hi,

I'm sorry, I don't know the way to do this in Netscape. I recommend that
you try a Netscape oriented newsgroup or chat room. Some can be found at
http://channels.netscape.com/ns/jump/community/default.jsp

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.


--------------------
 
Hi,

I'm sorry, I don't know the way to do this in Netscape. I recommend that
you try a Netscape oriented newsgroup or chat room. Some can be found at
http://channels.netscape.com/ns/jump/community/default.jsp

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.

Nuts. 95% of this application is used by back-end people. 100% IE. The
other 5% is publicly accessable so I need to get it working at least
there... or redirect them to comebackwitharealbrowser.htm.

:)
 
Back
Top