Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Tester for Extension</title>
        <script type="text/javascript">
            //note: we aren't using varMyKeyCode
            //var myKeyCode = 65; // should be "A"
            // var myKeyCode = 13; // should be RETURN
            function fireIt(){
                var el = document.getElementById("inputId");
                el.focus();
                var e = document.createEvent('KeyEvents');
                e.initKeyEvent('keypress', true, true, window, false, false, false, false, 0, 0x0c);
              // character A: 0x41
              // carriage return: 0x0d
              // new line: 0x0a
              // form feed: 0x0c
                var status = el.dispatchEvent(e);
                if(status) alert("dispatched2");
                else alert("status false");
              // note: this is always showing status false;
              // it showed dispatched2 when decimal keycodes were used
              // (but then no result was visible in the input element)
 }
        </script>
    </head>
    <body>
      <form name="myForm" action="http://example.com/nowhere.html" onsubmit="alert('submited');">
            <input type="button" value="button" onclick="fireIt()" />
            <input type="text" id="inputId" name="myInput" value="value" />
        </form>
    </body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers