Capturing Enter Key

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Muriel

    Capturing Enter Key

    I'm developing a website using visual studio .NET

    I have a login form with a couple of textboxes and a login button. What I
    want to do is capture the Enter key so that when the user presses Enter, it
    will click the submit button.

    I have searched the Internet for hours now trying to find out how to do it,
    but any methods that I have seen do not work.

    Can anyone help me do that?
  • Paul Henderson

    #2
    Re: Capturing Enter Key

    If your login button is just an <input type="submit" .../>, then I
    would expect it to respond to enter automatically. If, however, you are
    using ASP textbox controls, then problems seem to occur, particularly
    on esoteric browsers. If you are using an asp:HtmlButton or
    asp:HtmlInputBu tton, you could try using an asp:Button instead, as
    that's more likely to work. If that doesn't help, I would try adding a
    (client-side) onkeydown event that checks for character 13 (return),
    and if it detects it, calls the form's submit method.

    It'd be helpful if you could post the code for the page in question,
    though [and perhaps say what are the sorts of methods that did not
    work...].

    Comment

    • Muriel

      #3
      Re:Capturing Enter Key

      Never mind!!! I found a way using Javascript

      Comment

      • Muriel

        #4
        Re: Capturing Enter Key

        Well, there were too many things I had tried in order to capture the Enter
        Key. In the end, I used this Javascript:

        <SCRIPT>

        if (document.layer s)
        document.captur eEvents(Event.K EYDOWN);

        document.onkeyd own = function (evt)
        {
        var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) :
        event.keyCode;

        if (keyCode == 13)
        {
        document.Login1 470.cmdSubmit.c lick();
        return false;
        }
        else
        return true;
        };

        </SCRIPT>

        It works like a charm.

        Comment

        Working...