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

5399Re: [ydn-javascript] Attaching form onsubmit listener

Expand Messages
  • Adam Moore
    Oct 3, 2006
      On Mon, Oct 02, 2006 at 07:21:05PM +0000, foti-1@... wrote:
      > A more traditional form onsubmit event handler might look like this:
      > <form id="someForm" onsubmit="return validate();">
      > In other words, the result of the validate() function determines whether or not the form submits. Is this the correct way to do the same thing using the YUI Event Utility:
      > <script type="text/javascript" src="./yui/build/yahoo/yahoo.js"></script>
      > <script type="text/javascript" src="./yui/build/event/event.js"></script>
      > <script type="text/javascript" src="./yui/build/dom/dom.js"></script>
      > <script type="text/javascript">
      > function validate(e)
      > {
      > // Perform validation... if it fails, then call...
      > YAHOO.util.Event.stopEvent(e);
      > }
      > function attachBehaviors()
      > {
      > YAHOO.util.Event.on('someForm','submit',validate);
      > }
      > YAHOO.util.Event.on(window,'load',attachBehaviors);
      > </script>
      > In other words, since we can't "return" a value in our event handler, we instead either stop or don't stop the event. Would this be the correct way to do this?

      You are correct, calling stopEvent will accomplish what you are trying to
      do. Actually, it is preventDefault that is preventing the post:


      stopEvent also stops the event propagation, which is not relevant in this

    • Show all 5 messages in this topic