Welcome to WebmasterWorld Guest from 54.145.209.34

Forum Moderators: open

text input manipulation

   
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" />
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;
onode=that;
onode=onode.nextSibling;
while(onode) {
if (onode.nodeType==1) {
otarget=onode;
break;
}
onode=onode.nextSibling;
}
if (otarget) {
otarget.focus();
}
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..
 

Featured Threads

Hot Threads This Week

Hot Threads This Month