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

YUI button, form & preventDefault

Expand Messages
  • geoff2v
    Hello -- I m having a bit of trouble with the YUI Button module; specifically, how it s interacting with my a form submission and my effort to stop this
    Message 1 of 1 , Mar 31, 2009
    • 0 Attachment

      Hello --

      I'm having a bit of trouble with the YUI Button module; specifically, how it's interacting with my a form submission and my effort to stop this interaction.

      I have yet to come up with a test case, but here's a snippet of my code and hopefully there's something obviously wrong with it.

      Here's the code I'm using to transform form buttons (of the form input=etc.) into YUI buttons:

      YAHOO.util.Event.onDOMReady(function () {
      var i;
      var buttons = YAHOO.util.Dom.getElementsByClassName('button', 'input');
      for (i = 0; i buttons.length; i = i + 1) {
      if (buttons[i].id != 'zipbutton') {
      new YAHOO.widget.Button(buttons[i]);
      }

      }
      });

      And here's the code I'm using to intercept the submission action of one of my form buttons:

      YAHOO.util.Event.onAvailable('ignorebutton', ignoreInit);

      function ignoreInit() {
      var ignorebutton = YD.get('ignorebutton');
      YAHOO.util.Event.addListener(ignorebutton, 'click', ignore);
      }


      function ignore(e) {
      YAHOO.util.Event.preventDefault(e);
      alert("Are you sure you want to ignore this change?");
      }


      (Sorry, had trouble keeping identation.)

      Now, when I click on the "ignorebutton" (which actually is a submit button), the alert comes up, but the submission takes place underneath; the default action is not actually prevented. However, if I remove the line in bold above, and thereby keeping a non-YUI, standard form submission input button, then the remainder of the code works properly and the default action is intercepted.

      Any thoughts as to what I'm doing wrong? I had some problems earlier with invalid buttons which related to the fact that I had the form opening tag inside a table, but I resolved that.

      Many thanks.

    Your message has been successfully submitted and would be delivered to recipients shortly.