Default button in web form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Leo Smith
    New Member
    • Mar 2007
    • 45

    Default button in web form

    Is there a way to set a button as default in a web form? Current issue is that a return pressed while in the form sends a form submit. This is fine, except I do not want to send a full postback. I am trying to override the postback and use an AJAX call instead. I tried capturing the keypress event in the text box, but it still is requesting a full page submit back to the server (even though I am using an input tag with a button type).

    Thanks,
    Leo
  • drhowarddrfine
    Recognized Expert Expert
    • Sep 2006
    • 7434

    #2
    Not with html/css. I'll send this to javascript board.

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5390

      #3
      hi ...

      please post the code you already have so that we may have a closer look at your problem ...

      kind regards

      Comment

      • Leo Smith
        New Member
        • Mar 2007
        • 45

        #4
        I have a simple question. I actually fixed the problem only because the callback for the AJAX call failed due to the event was not fired from the button click. I then took the failure and ensured that it did the click call on the button, thus sending the proper message.

        The question is which event fires when you hit return in an input element (type text)? It doesn't seem to be the onsubmit event for the form or a onkeypress event on the control (neither of these fired when I was trying to deal with the problem). It also doesn't fire the onclick event for a button that even if it is the only button on the page.

        By the way, the main browser that is causing the problem is Firefox (Windows and MAC versions, all point releases), with IE 7.0 sometimes failing. The error does return to the AJAX failed function.


        Thanks,
        Leo

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5390

          #5
          hi ...

          you may use the keypress-event:

          [HTML]<script>
          function handle_keypress (e) {
          var val = typeof window.event != 'undefined' ? window.event.ke yCode : e.keyCode;
          alert(val);
          }
          </script>
          <input type="text" onkeypress="han dle_keypress(ev ent);"/>
          [/HTML]
          kind regards

          Comment

          Working...