focus to change from texbox to texbox

Hello,

my users are entering SSN number.
To not complicate with a Mask, I simply split SSN number entry into 3 entry textbox fields.

Ideally, when user enters 3 digits into first textbox, then cursor would automatically jump to next textbox where users would ented 2 digits and then would jump to third textbox.

How I can achieve this "cursor jumping" ?

Thank you
TerraceAsked:
Who is Participating?
 
Asim NazirCommented:
0
 
mkobrinCommented:
On the text changed event you can check the length of the string, and if it is the correct length then you can set focus on the next text box

Something like this

if(text1.Text.Length > 2)
    text2.Focus();

on the second one:
if(text2.Text.Length > 1)
    text3.Focus();
0
 
Asim NazirCommented:
Instead of > better use == operator. So code will become:

if(text1.Text.Length == 3)
    text2.Focus();

on the second one:
if(text2.Text.Length == 2)
    text3.Focus();
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
TerraceAuthor Commented:
Thank you for answers.
I was planning to do it that way, however what is the exact command to force focus in the textbox.

Sorry, I forgot to mention in my question that I am using VB.NET and Visual Studio 2003

The text2.focus()  does not work.

Alert/erorr says:   'focus' is not member of 'System.Web.UI.Webcontrols.textbox'

I hope VS2003 has a built in function for focus, otherwise I have to use some java script or similar. (hopefully not)

what should go after text2.   to please VS2003 ?

Thanks
0
 
TerraceAuthor Commented:
Thanks.

This is supported in .NET Framework 2.0 and above.

Even we plan to upgrade this entire project to 3.5 soon, currently we are in .NETFramework 1.1 still.

Any other suggestions ?

if not built in control, what java script I could use and how ?

Thanks
0
 
Asim NazirCommented:
Try this then:

<script>
var txtBox=document.getElementById("ctl00_txtUserName" );
if (txtBox!=null ) txtBox.focus();
</script>

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.