Toggle enter key

Discussion in 'ASP .Net' started by DavidC, Mar 4, 2010.

  1. DavidC

    DavidC Guest

    I have an asp.net web page with the javascript below at the top of the page.
    This works great as a user hitting the <enter> key is not "posted" and
    subsitutes the tab key. However, when the user lands on the submit button
    (called BtnSave) I want the <enter> key to act as normal. Does anyone know a
    way to do this? Thanks.

    <script type="text/javascript">
    document.onkeydown = doKey;

    function doKey(e) {
    if (event.keyCode == 13) {
    event.keyCode = 9;
    return event.keyCode;
    }
    }
    </script>


    --
    David
    DavidC, Mar 4, 2010
    #1
    1. Advertising

  2. On Mar 4, 3:42 pm, DavidC <> wrote:
    > I have an asp.net web page with the javascript below at the top of the page.
    > This works great as a user hitting the <enter> key is not "posted" and
    > subsitutes the tab key.  However, when the user lands on the submit button
    > (called BtnSave) I want the <enter> key to act as normal.  Does anyone know a
    > way to do this?  Thanks.
    >
    >     <script type="text/javascript">
    >         document.onkeydown = doKey;
    >
    >         function doKey(e) {
    >             if (event.keyCode == 13) {
    >                 event.keyCode = 9;
    >                 return event.keyCode;
    >             }
    >         }
    >     </script>
    >
    > --
    > David


    What happens if you add an event handler directly to the button?

    onkeypress="..." onClick="..."
    Alexey Smirnov, Mar 4, 2010
    #2
    1. Advertising

  3. DavidC

    DavidC Guest

    Javascript is not my strong suit, but I added onkeypress="togglenter();" to
    my button and the js function below and it did not work. When I pressed
    <enter> when on the button it just issued a TAB to the next control. Can you
    spot what I am doing wrong? Thanks.

    function togglenter() {
    if (event.keyCode == 13) {
    event.keyCode = 13;
    return event.keyCode;
    }
    }

    --
    David


    "Alexey Smirnov" wrote:

    > On Mar 4, 3:42 pm, DavidC <> wrote:
    > > I have an asp.net web page with the javascript below at the top of the page.
    > > This works great as a user hitting the <enter> key is not "posted" and
    > > subsitutes the tab key. However, when the user lands on the submit button
    > > (called BtnSave) I want the <enter> key to act as normal. Does anyone know a
    > > way to do this? Thanks.
    > >
    > > <script type="text/javascript">
    > > document.onkeydown = doKey;
    > >
    > > function doKey(e) {
    > > if (event.keyCode == 13) {
    > > event.keyCode = 9;
    > > return event.keyCode;
    > > }
    > > }
    > > </script>
    > >
    > > --
    > > David

    >
    > What happens if you add an event handler directly to the button?
    >
    > onkeypress="..." onClick="..."
    > .
    >
    DavidC, Mar 4, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bsm
    Replies:
    0
    Views:
    1,304
  2. BrianDH

    Enter Key H*ll, control enter key submit button

    BrianDH, Jan 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    389
    Anders Matthiessen
    Jan 12, 2005
  3. M P
    Replies:
    1
    Views:
    466
  4. Matt
    Replies:
    1
    Views:
    505
    Michael Winter
    Mar 6, 2004
  5. HopfZ
    Replies:
    0
    Views:
    562
    HopfZ
    Aug 28, 2006
Loading...

Share This Page