Loading ...
Sorry, an error occurred while loading the content.

Re: [ydn-javascript] Unable to stop form submit

Expand Messages
  • Todd Kloots
    Kel - It is a bug in Button that is fixed in the latest release of YUI (2.6.0). You can also work around this problem by not using an inline onsubmit event
    Message 1 of 1 , Oct 1, 2008
    • 0 Attachment
      Kel -

      It is a bug in Button that is fixed in the latest release of YUI
      (2.6.0). You can also work around this problem by not using an inline
      "onsubmit" event handler, but by adding a "submit" event handler to your
      form via the Event Utility's "on" method. For example, assuming your
      form tag has an id of "my-form", the handler would look like:

      YAHOO.util.Event.on("my-form", "submit", function (e) {

      // Stop the form from submitted by using preventDefault
      YAHOO.util.Event.preventDefault(e);

      });

      Remember - inline event handlers are a bad practice. If you haven't
      already, read this article:

      http://en.wikipedia.org/wiki/Unobtrusive_JavaScript

      - Todd



      Kel wrote:
      >
      > I'm having problems with a form submitting when <enter> is pressed,
      > even though I set the form's onSubmit to return false. I am using
      > IE7, and when I remove the code that transforms the button to a YUI
      > button, it works fine. Here's an example:
      >
      > <HTML>
      > <HEAD>
      > <link rel="stylesheet" type="text/css"
      > href="yui/build/button/assets/skins/sam/button.css">
      > <script type="text/javascript" src="yui/build/yahoo-dom-event/yahoo-
      > dom-event.js"></script>
      > <script type="text/javascript" src="yui/build/element/element-beta-
      > min.js"></script>
      > <script type="text/javascript" src="yui/build/button/button-
      > min.js"></script>
      > </HEAD>
      > <BODY CLASS='yui-skin-sam'>
      > <FORM NAME='f' onsubmit='return false;'>
      > <INPUT NAME='name' TYPE='TEXT' SIZE='20'>
      >
      > <input type='button' id='mybutton' name='mybutton' value='Save'>
      > <script type='text/javascript'>
      > var oButton = new YAHOO.widget.Button('mybutton');
      > </script>
      > </FORM>
      > </BODY></HTML>
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.