user3515102
user3515102

Reputation: 43

press TAB by code

i try make press TAB by code; how can complete the code after 1 second automatic press (tab)

if(keycode == '13'){

setTimeout( function(){ 

**// press tab automatic**


} , 1000 );

}
event.stopPropagation();
});

Upvotes: 0

Views: 1012

Answers (2)

Morix Dev
Morix Dev

Reputation: 2724

A viable solution is available here.

Here is an example coming from the given link:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

    <script type="text/javascript">
      /*************************************************
       * Example showing how to simulate pressing a key.
       *************************************************/

      function pressChar(char)
      {
        try
        {
          // Create the key press event.
          var pressEvent = document.createEvent('KeyboardEvent');
          pressEvent.initKeyEvent("keypress", true, true, window, 
                                    false, false, false, false, 
                                    0, char.charCodeAt(0));

          var input = document.getElementById('input_field'); // Get the element where you want to press.

          input.dispatchEvent(pressEvent); // Press the key.
        }
        catch (e) {
            alert ("Your browser does not support this example!");
        }
      }
    </script>


    <title>Simulate pressing a key</title>
  </head>

  <body>
    <button onclick="pressChar('s')">Simulate pressing the 's' key in the input field.</button>
    <input type="text" id="input_field" />
  </body>

</html>

Please mark this answer as accepted if it responds your question.

Upvotes: 1

Cagy79
Cagy79

Reputation: 1620

\t is a tab character but it won't send a TAB key to move to a next object.

I think you need an automation tool like Selenium IDE?

Upvotes: 0

Related Questions