homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

text input manipulation

Msg#: 4367713 posted 11:09 am on Sep 27, 2011 (gmt 0)

Hi there, I have a form where I need to split up a number input into 4 text inputs (so the user can enter the 16 digits long number in groups of 4). I am trying to get the relevant textbox selected (highlighted) everytime it gains focus, as well as automatically switching to the next textbox after entering 4 characters. Here's what I have:
Four of these:
<input type="text" onfocus="this.select();" class="kurzinput" name="sc2" onkeyup="next(this);" maxlength="4" />



Msg#: 4367713 posted 11:14 am on Sep 27, 2011 (gmt 0)

oops i hit submit instead of preview.. sorry, so here's the continuation:
the javascript for next:
function next(that) {
if(document.selection == undefined) {
if(that.value.length == 4){
var onode, otarget;
while(onode) {
if (onode.nodeType==1) {
if (otarget) {
else {}

the inputs may contain information fetched from a db. The problem is if there is info already in them, and the user is tabbing their way into the first textbox, it gets selected and then jumps straight to the next textbox coz there already are 4 characters in it. If I don't select the content of the textbox onfocus, it's not jumping to the next textbox before it should. That's why i'm trying to check the selection with document.selection == undefined, which i guess is not right..

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved