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 3 of 3

Thread: not selecting

  1. #1
    New to the CF scene
    Join Date
    Jun 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy not selecting

    I am trying to move from one input box to another and then select the text in it. Below is a simplified version of what I'm trying to do. How come I can't select() the text when the focus comes from another input box, but will select() if I am already in the box? This is really weird

    // sample code
    PHP Code:
    <html>
    <
    head>
    <
    script type="text/javascript">
    function 
    moveToB() {
        
    //get the key pressed in Netscape and IE
        
    var keyCode 
        
    document.layers evt.which :
        
    document.all event.keyCode :
        
    document.getElementById evt.keyCode 0;
        
        if (
    keyCode == 40) { // down arrow pressed
            
    var obj document.getElementById('b');
            
    obj.focus();
            
    //why doesn't this work??
            
    obj.select();
        }
    }
    </script>
    </head>
    <body>
    press the <b>down arrow</b> to move from box A to box B<br>
    <form name="f">
    <input type="text" id="a" onkeydown="moveToB()" value="boxA">
    <input type="text" id="b" onkeydown="moveToB()" value="boxB">
    </form>
    moving from box A to B will not select the text in B, however moving from box B to B will.
    </body>
    </html> 

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    use onkeyup instead
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #3
    New to the CF scene
    Join Date
    Jun 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sweet!! I couldn't figure that out for the longest time... and to think, all I had to do was ask!


  •  

    Posting Permissions

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