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

Attaching form onsubmit listener

Expand Messages
  • foti-1@comcast.net
    A more traditional form onsubmit event handler might look like this: In other words, the result of the
    Message 1 of 5 , Oct 2, 2006
    • 0 Attachment
      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?
      Thanks,
      Peter
    • fotiman2000
      Anyone? ... whether or not the form submits. Is this the correct way to do the ... src= ./yui/build/yahoo/yahoo.js ...
      Message 2 of 5 , Oct 3, 2006
      • 0 Attachment
        Anyone?


        --- In ydn-javascript@yahoogroups.com, 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?
        > Thanks,
        > Peter
        >
      • Adam Moore
        ... You are correct, calling stopEvent will accomplish what you are trying to do. Actually, it is preventDefault that is preventing the post:
        Message 3 of 5 , Oct 3, 2006
        • 0 Attachment
          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:

          YAHOO.util.Event.preventDefault(e);

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


          -Adam
        • dav.glass@yahoo.com
          Peter -- Yes, you can handle it that way.. Usually, I will stop the event all the time & have my listener submit the form.. But either way works.. Dav Glass
          Message 4 of 5 , Oct 3, 2006
          • 0 Attachment
            Peter --
            Yes, you can handle it that way..

            Usually, I will stop the event all the time & have my listener submit the form..

            But either way works..
             
            Dav Glass
            dav.glass@...
            davglass.com
            618.694.3476

            + Windows: n. - The most successful computer virus, ever. +
            + A computer without a Microsoft operating system is like a dog
            without bricks tied to its head +
            + A Microsoft Certified Systems Engineer is to computing what a
            McDonalds Certified Food Specialist is to fine cuisine +


            ----- Original Message ----
            From: fotiman2000 <foti-1@...>
            To: ydn-javascript@yahoogroups.com
            Sent: Tuesday, October 3, 2006 10:08:56 AM
            Subject: [ydn-javascript] Re: Attaching form onsubmit listener

            Anyone?

            --- In ydn-javascript@ yahoogroups. com, 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/javascri pt"
            src="./yui/build/ yahoo/yahoo. js"></script>
            > <script type="text/javascri pt"
            src="./yui/build/ event/event. js"></script>
            > <script type="text/javascri pt"
            src="./yui/build/ dom/dom.js" ></script>
            > <script type="text/javascri pt">
            > 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',attachBeh aviors);
            > </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?
            > Thanks,
            > Peter
            >


          • foti-1@comcast.net
            Thanks Dav and Adam Moore for your replies. :) -Peter ... From: ... Peter -- Yes, you can handle it that way.. Usually, I will stop the
            Message 5 of 5 , Oct 3, 2006
            • 0 Attachment
              Thanks Dav and Adam Moore for your replies. :)

              -Peter


              -------------- Original message ----------------------
              From: <dav.glass@...>
              > Peter --
              > Yes, you can handle it that way..
              >
              > Usually, I will stop the event all the time & have my listener submit the form..
              >
              > But either way works..
              >
              > Dav Glass
              > dav.glass@...
              > davglass.com
              > 618.694.3476
              >
              > + Windows: n. - The most successful computer virus, ever. +
              > + A computer without a Microsoft operating system is like a dog
              > without bricks tied to its head +
              > + A Microsoft Certified Systems Engineer is to computing what a
              > McDonalds Certified Food Specialist is to fine cuisine +
              >
              > ----- Original Message ----
              > From: fotiman2000 <foti-1@...>
              > To: ydn-javascript@yahoogroups.com
              > Sent: Tuesday, October 3, 2006 10:08:56 AM
              > Subject: [ydn-javascript] Re: Attaching form onsubmit listener
              >
              > Anyone?
              >
              > --- In ydn-javascript@ yahoogroups. com, 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/javascri pt"
              > src="./yui/build/ yahoo/yahoo. js"></script>
              > > <script type="text/javascri pt"
              > src="./yui/build/ event/event. js"></script>
              > > <script type="text/javascri pt"
              > src="./yui/build/ dom/dom.js" ></script>
              > > <script type="text/javascri pt">
              > > 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',attachBeh aviors);
              > > </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?
              > > Thanks,
              > > Peter
              > >
              >
              >
              >
              >
              >
              >
            Your message has been successfully submitted and would be delivered to recipients shortly.