button focus and pressing enter

Discussion in 'ASP .Net' started by Philip Townsend, Aug 25, 2003.

  1. Can anybody tell me how I can disable the enter (keyboard) button from
    being able to submit a form? In other words, force the user to click a
    button with the mouse?

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Philip Townsend, Aug 25, 2003
    #1
    1. Advertising

  2. Philip Townsend

    karl Guest

    Heres a simple way, not the best way maybe.

    <script language="javascript">
    function keyPress()
    {
    if (event.keyCode == 13)
    {
    event.returnValue = false;
    }
    }
    </script>


    <body onkeypress="KeyPress();">
    or you can specify each textbox, etc.. by placing code like this in the
    Page_Load Event
    this.tbCode.Attributes.Add("onkeypress", "keyPress();");

    the same technique can be used to fire an event like save, or search
    function keyPress()
    {
    if (event.keyCode == 13)
    {
    event.returnValue = false;
    document.getElementById("btnDoSearch").click();
    }
    }

    Karl



    "Philip Townsend" <> wrote in message
    news:Os3sx%...
    > Can anybody tell me how I can disable the enter (keyboard) button from
    > being able to submit a form? In other words, force the user to click a
    > button with the mouse?
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    karl, Aug 25, 2003
    #2
    1. Advertising

  3. It seems as if the onkeypress event is not even firing...

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Philip Townsend, Aug 25, 2003
    #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. Philip Townsend

    button focus and pressing enter

    Philip Townsend, Aug 14, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    8,748
  2. Dan Brussee

    Default button - pressing Enter

    Dan Brussee, Feb 19, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    446
  3. Neo
    Replies:
    2
    Views:
    3,189
    bruce barker
    May 11, 2004
  4. George Homorozeanu
    Replies:
    1
    Views:
    342
    Brock Allen
    Jul 19, 2005
  5. GOKU24
    Replies:
    0
    Views:
    142
    GOKU24
    Aug 26, 2003
Loading...

Share This Page