Results 1 to 5 of 5

Thread: textbox focus

  1. #1

    Thread Starter
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    textbox focus

    hi to everyone im very new in this thing.
    why this code wont work?
    whats wrong w/ it?
    what i want to achieve is when i hit the enter key it will get focus to another textbox..
    PHP Code:
    <form>
        <
    input type="textbox" name="textbox1" onkeypress="keydown(event)" >
        <
    input type="textbox" name="textbox2">
    </
    form>
    <
    script>
        function 
    keydown(e){
         if (!
    e) var window.event;
        if (
    e.keyCodecode e.keyCode;
        else if (
    e.whichcode e.which;
        if (
    code==13){
        
    textbox2.focus();
        }
        }
    </
    script
    thanks in advance guys..
    more power

  2. #2
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    it said textbox2 is undefined. This is because you've addressed the thing wrongly, this will work:
    Code:
    <form>
        <input type="textbox" id="textbox1" onkeypress="keydown(event)" >
        <input type="textbox" id="textbox2">
    </form>
    <script>
        function keydown(e){
         if (!e) var e = window.event;
        if (e.keyCode) code = e.keyCode;
        else if (e.which) code = e.which;
        if (code==13){
        document.getElementById('textbox2').focus();
        }
        }
    </script>
    Have I helped you? Please Rate my posts.

  3. #3

    Thread Starter
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416
    hi acidic i tried what you have given me but still it wont work..
    what's wrong w/ it?
    PHP Code:
    <form>
        <
    input type="textbox" name="textbox1" onkeypress="keydown(event)">
        <
    input type="textbox" name="textbox2">
    </
    form>
    <
    script language="javascript">
        function 
    keydown(e){
        if (!
    e) var window.event;
        if (
    e.keyCodecode e.keyCode;
        else if (
    e.whichcode e.which;
        if (
    code==13){
        
    document.getElementById("textbox2").focus();
        }
        }
    </
    script
    sorry for my stupidity im very new in this thingy.

  4. #4
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    what I posted did work. look at the function getElementByID(). You need to specify an id, not a name, for puposes on server-side code maybe you need both id and name attributes.

    so change thos names back to ids and you're off.
    Have I helped you? Please Rate my posts.

  5. #5

    Thread Starter
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416
    thanks man...


    works perfect

Posting Permissions

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



Click Here to Expand Forum to Full Width