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

Thread: onkeydown enter

  1. #1
    New Coder
    Join Date
    May 2008
    Posts
    70
    Thanks
    9
    Thanked 0 Times in 0 Posts

    onkeydown enter

    Hi, i'm trying to do this. When enter is clicked, the image with the specific javascript will function. Its basically a login page but with image as a button. I used <img src="blah.jpg" onclick="login()"> and the login() javascript is document.login.submit(); Now as we all login, we always click the enter button after typing our usernames and password, i would like to know how do i use javascript to do so. Can someone direct me? I've tried searching google but they only show example on something else like in w3schools, they only show how to deny the numbers character with the onkeydown event. There is only 1 example. Can someone guide me? Thanks.

  • #2
    New Coder
    Join Date
    May 2008
    Posts
    70
    Thanks
    9
    Thanked 0 Times in 0 Posts
    I think i got it
    Code:
    <SCRIPT>
    if (document.layers)
      document.captureEvents(Event.KEYDOWN);
    document.onkeydown =
      function (evt) {
        var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : 
    event.keyCode;
        if (keyCode == 13) {
          document.aForm.submit();
          return false;
        }
        else
          return true;
      };
    
    </SCRIPT>
    but can someone explain how it functions? Please.


  •  

    Posting Permissions

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