Welcome to WebmasterWorld Guest from 23.20.241.155

Forum Moderators: open

Message Too Old, No Replies

focus on next textbox after entering restricted number of chars

     
1:47 pm on Jul 22, 2011 (gmt 0)



Hi again :-)

I was asked to change the way user enters a 12 digit number, to spread it across 3 textboxes for better readability, with automatically moving to next textbox when the permitted number of chars/textbox is reached. I have a function called on an onkeyup event of each of the textboxes, the function looks like this:

function next(obj) {
if(obj.value.length == 4) {
var nextnode, target;
nextnode=obj;
nextnode=nextnode.nextSibling;
while(nextnode) {
if (nextnode.nodeType==1) {
target=nextnode;
break;
}
nextnode=nextnode.nextSibling;
}
if (target) {
target.focus();
}
else {}
}
}


This works fine as long as there is nothing in the textboxes originally. The trouble is, in some cases, I need to retrieve that 12 digit value from a db, display it in the textboxes and then let the user change it if they want. In this case, I have set the onfocus event of the textboxes to onfocus="this.select();", so that once the user enters a textbox, he doesn't need explicitly delete its contents before typing something new.
As soon as any of them textboxes get focus, the above code causes the focus to move to the next textbox immediately since the length is already 4. I have tried to change the code to:
if(obj.value.length == 4 && document.selected == undefined)

to make sure it's only executed if the text in the box is not selected any more(and the user actually started typing), but it's useless.. I was wondering if a former listbox selection could interfere with it (giving document.selected other value than undefined) but I get the feeling that the problem lies somewhere else.. Help! Hilfeeeee! :-)
1:51 pm on Jul 22, 2011 (gmt 0)



i'm using FF and the mysterious thing is, that it actually works if I click into the first of those textboxes. Works like a charm. But if i tab my way into the textbox, the thing with the tboxjumping happens... I'm really lost here :-]
10:46 am on Aug 3, 2011 (gmt 0)



okay forget it..
 

Featured Threads

Hot Threads This Week

Hot Threads This Month