javascript/ change enter key to tab keypress

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rrosebro
    New Member
    • Apr 2006
    • 2

    javascript/ change enter key to tab keypress

    this work great and stops all enter key presses. now how do i disable the event and fire a tab key event.
    so if a user presses the enter key i need it to be ignore and tab to the next field.

    <head>
    <script type="text/javascript">

    function kH(e) {
    <!--
    var pK = document.all? window.event.ke yCode:e.which;
    return pK != 13;
    }

    document.onkeyp ress = kH;
    if (document.layer s) document.captur eEvents(Event.K EYPRESS);
    file://-->
    </script>
    </HEAD>
  • rrosebro
    New Member
    • Apr 2006
    • 2

    #2
    here is code that works! must be in body tag.
    <body> onkeydown="if (event.keyCode= =13) {event.keyCode= 9; return event.keyCode }"

    Comment

    • freedude
      New Member
      • Jun 2006
      • 1

      #3
      Originally posted by rrosebro
      here is code that works! must be in body tag.
      <body> onkeydown="if (event.keyCode= =13) {event.keyCode= 9; return event.keyCode }"
      The above code was a lot help. But in my web page I have to also access the links using keyboard. In that case I have to use the alt + access key and then press enter to access a particular link. So if I use the above code then I am not able to access the links using keyboard.

      Comment

      • chilakala
        New Member
        • Feb 2007
        • 3

        #4
        This Code is Working Fine with all controls , means the Focus is moving to Next Control. BUT this is not working When the Focus is in "HtmlInput File"Control which we will use for File UpLoadings. means Focus is not moving to Next Control. Then How to modify code.


        Originally posted by rrosebro
        this work great and stops all enter key presses. now how do i disable the event and fire a tab key event.
        so if a user presses the enter key i need it to be ignore and tab to the next field.

        <head>
        <script type="text/javascript">

        function kH(e) {
        <!--
        var pK = document.all? window.event.ke yCode:e.which;
        return pK != 13;
        }

        document.onkeyp ress = kH;
        if (document.layer s) document.captur eEvents(Event.K EYPRESS);
        file://-->
        </script>
        </HEAD>

        Comment

        • asipo
          New Member
          • Jun 2008
          • 1

          #5
          actually the code provide by rrosebro is not working for me =.=

          and i try alot with that kind of coding where u try to set the 13 into 9

          and i think the web browser ( im using mozilla firefox 2.0.0.14 ) not allowing us to change that

          so heres my code to solve the enter as tab ( using an id as element )


          at the script part
          Code:
                 function testing(event,number)
          	{
          		if( event.keyCode == 13 )
          		{
          			var wow = document.getElementById(number);
          			wow.focus();
          		}		
          	}

          so the input will look like this
          Code:
          <form>
                    <input id="1" type="text" tabindex="1" onkeyup="testing(event,2)" />
                    <input id="2" type="text" tabindex="3" onkeyup="testing(event,3)" />
                    <input id="3" type="text" tabindex="2" onkeyup="testing(event,1)" />
          </form>

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Welcome to Bytes and thanks for sharing.

            Remember that IDs should not start with or be only numbers, so use a string not starting with a number.

            Comment

            • sheryarnizar
              New Member
              • Jul 2008
              • 1

              #7
              its too simple dear,
              in body tag just add this
              <body onkeydown="if (event.keyCode= =13) {event.keyCode= 9; return event.keyCode }">

              DONE!.. :) Now your ENTER key will be treated as TAB key to focus other controls..

              Regards
              Sheryar Nizar
              [url removed]
              Last edited by acoder; Jul 17 '08, 06:02 PM. Reason: removed link

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Are you sure about that? Have you tested on browsers besides IE? What about textareas?

                I've removed the link in your post. Please read the Posting Guidelines.

                Comment

                • Logician
                  New Member
                  • Feb 2007
                  • 210

                  #9
                  Originally posted by rrosebro
                  this work great and stops all enter key presses. now how do i disable the event and fire a tab key event.
                  so if a user presses the enter key i need it to be ignore and tab to the next field.
                  Try using EnterToTab

                  Comment

                  Working...