Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    PMB
    PMB is offline
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Transfering ths focus to next Field

    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?

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,145
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    Try this:-

    Code:
    <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

  • #3
    PMB
    PMB is offline
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's working now.Thank u

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,145
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    Quote Originally Posted by PMB View Post
    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:-

    Code:
    <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();
    }
    }
    Last edited by Philip M; 03-18-2009 at 12:33 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •