473,408 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

JavaScript: Move focus on keypress if textfield is finished

210 Expert 100+
I have a form where users will input phone numbers. The way it is set up is with three text boxes. First for phone prefix( 314) then second for the middle number (546) and finally third for last four digits (4563). What i am being asked to do is the cursor need to jump to second text box as soon as user inputs 3 digits on the first text box. and so on. Is there a way to accomplish this. Please help!!

Thank you in advance.
Feb 5 '08 #1
9 5259
Plater
7,872 Expert 4TB
You can but you need to be pretty carefull about it.
You need to watch the keypress events for the textboxes (javascript event)
Then you have to watch to see if:
A) the maximum allowed characters are already in the box (for the first box it would be 3)
B) that the key being pressed is a character key and not a control key (like arrow keys, backspace, delete, etc, etc) so that you don't keep jumping to another textbox when someone presses the arrow key.
Then if the end is reached, set focus to your next control.

The folks over in the javascript section might be able to explain it a bit better.
Feb 5 '08 #2
semomaniz
210 Expert 100+
Thanks ,

This means that i will have to use AJAX for this. I know how to do this in classic asp but i am new to AJAX so way confused . Isnt there any other simple solution ??
Feb 5 '08 #3
Plater
7,872 Expert 4TB
Well, you don't HAVE to use ajax for this. I don't think you need to have it keep coming back to the server for anything?
Feb 5 '08 #4
semomaniz
210 Expert 100+
can you provide me with example on how can it be done? please
Feb 5 '08 #5
Plater
7,872 Expert 4TB
I will do you one better and move the question over to the section where people could give you a good example.

MODERATOR
Feb 6 '08 #6
acoder
16,027 Expert Mod 8TB
Here's a good example.
Feb 6 '08 #7
semomaniz
210 Expert 100+
The posting is for simple html form. Can you please provide me with the example on how to do this with asp.net form.

thank you in advance.
Feb 6 '08 #8
Plater
7,872 Expert 4TB
The posting is for simple html form. Can you please provide me with the example on how to do this with asp.net form.

thank you in advance.
Same thing. ASP.NET still just makes a regular HTML form.
And you're going to be doing this with javascript anyway.
Feb 6 '08 #9
acoder
16,027 Expert Mod 8TB
Yes, that's right. When the server-side code gets to the browser it's been translated/converted into client-side HTML markup. View source in your browser and you'll see.
Feb 7 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: francisco lopez | last post by:
ok , first of all sorry if my english is not so good, I do my best. here is my problem: I don´t know much javascript so I wrote a very simple one to validate a form I have on my webpage. ...
7
by: Seash | last post by:
Hi friends , here is the sample code private void txtbox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if(e.KeyChar == 13) //enter { txtbox2.Focus(); }
7
by: CharlesA | last post by:
Hi folks, first off, I'm using .Net framework 1.1 with ASP.net and C# I'm trying to do something very simple...but I can't figure it out I have an <asp:button runat="server"> in the test...
7
by: julian.tklim | last post by:
Hi, I need to build an editable Datagrid with add & delete buttons on each row using javascript. DataGrid need not be pre-populated with values. To make the thing complicated, one of the...
1
by: paulsson | last post by:
Does anyone know why placing the cursor/focus in a textfield in IE would cause the window.onblur event handler to be called? This seems very odd since the window still has focus.... Is there a way...
5
by: Morten Snedker | last post by:
I'm not that great at reading javascripts. Instead of doing nothing I'd like to return a Tab-character, if Enter occurs: <script language="javascript" type="text/javascript" > //disable...
1
by: lolly | last post by:
hi i recently used a virtual keyboard from www.codeproject.com/jscript/jvk.asp. However this part of the code function keyb_callback(ch) { var text =...
1
by: prathna | last post by:
Hi all, I would like to know how to pass a form bean value to javascript function to perform some validation.. I have a dropdown list and a textfield. I have created the dropdown list using...
1
by: Kid Programmer | last post by:
Hello guys. I was wondering how you make an event happen when the user presses a key. I have seen code used for this but I don't understand how it works. Here is the code in a sample I found:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.