...

View Full Version : Transfering ths focus to next Field



PMB
03-18-2009, 08:51 AM
I have 2 fields for phone number.one is of size 3 and another is 7.After reaching maximum size for first field it automatically focus next field.I coded it as

------------------------------------------------------

<input type="text" name="phone1" id="phone1" size="3" maxlength="3" class="resultable_text" onfocus = "setFlagForTextFieldFocus();" onkeyPress="KeyPress(this,event,3,'document.openaccount.phone2.focus();"/>

<input type="text" name="phone2" id="phone2" size="7" maxlength="7" class="resultable_text" onfocus = "setFlagForTextFieldFocus();"/>

------------------------------------------------------

function KeyPress(what,e,max,action) {



if (document.layers) {

if (e.target.value.length >= max){

if(isTextFieldFocused != true){

eval(action);

return;

}

}

isTextFieldFocused = false;

}else if (document.all) {

if (what.value.length > (max-1)){

if(isTextFieldFocused != true){

eval(action);

return;

}

}

isTextFieldFocused = false;

}else if (e.which){

if (e.target.value.length > (max-2)){

if(isTextFieldFocused != true){

eval(action);

return;

}

}

isTextFieldFocused = false;

}

}


-----------------------------------------------------

In Mozilla I am getting these errors

Error: Permission denied to get property XULElement.popupOpen
Error: Permission denied to set property XULElement.selectedIndex

is my code is wrong?

Philip M
03-18-2009, 09:42 AM
Try this:-


<input type = "text" id = "phone1" size = "3" maxlength = "3" onkeyup = "moveit()">
<input type = "text" id = "phone2" size = "7" maxlength = "7" >

<script type = "text/javascript">

function moveit() {
var a = document.getElementById("phone1").value;
if (a.length == 3) {
document.getElementById("phone2").focus();
}
}

</script>


It is your responsibility to die() if necessary….. - PHP Manual

PMB
03-18-2009, 01:01 PM
It's working now.Thank u

Philip M
03-18-2009, 01:07 PM
It's working now.Thank u

I take it that you realise that there is nothing to prevent the user from entering alpha characters, symbols and/or spaces in the boxes? You will need to validate these.

Suggest:-


<input type = "text" id = "phone1" size = "3" maxlength = "3" onkeyup = "numsOnly(this); moveIt(this)">
<input type = "text" id = "phone2" size = "7" maxlength = "7" onkeyup = "numsOnly(this)">

<script type = "text/javascript">

function numsOnly(which) {
var a = which.value;
var len = a.length;
if (/[^0-9]/.test(a)) {
alert ("Only numbers my be entered in this box");
which.value = a.substring(0,len-1);
return false;
}
}

function moveIt(which) {
var len = which.value.length;
if (len == 3) {
document.getElementById("phone2").focus();
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum