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

How to fire event listners programatically?

Expand Messages
  • wizhippo
    I want to fire the event listers for a an onChange event on a textbox so i have YAHOO.util.Event.addListener( check-in , change ,
    Message 1 of 4 , Nov 1, 2007
    • 0 Attachment
      I want to fire the event listers for a an onChange event on a textbox

      so i have

      YAHOO.util.Event.addListener("check-in", "change",
      YAHOO.tocom.quickSearch.validateDates);

      in another event i change the value of the text box but the onchange
      does not get fired.

      var txtDate1 = document.getElementById("check-out");
      txtDate1.value = month + "/" + day + "/" + year;

      This does not fire the onchange event.

      Do I have to do this to call all the eventlistners attached to the
      element?

      var listeners = YAHOO.util.Event.getListeners(txtDate1,
      "change");
      for (var i=0; i<listeners.length; ++i) {
      var listener = listeners[i];
      listener.fn(txtDate1);
      }



      or is there a simpler way?
    • wizhippo
      This is very frustrating. How do I fire an onclick event from within javascript? I thought I should be able to do this but no.
      Message 2 of 4 , Nov 2, 2007
      • 0 Attachment
        This is very frustrating.


        How do I fire an onclick event from within javascript?

        I thought I should be able to do this but no.

        document.getElementById("test").onclick();


        Please, any ideas would be a great help.
      • Gopal Venkatesan
        ... document.getElementById( test ).click(); -- Gopal Venkatesan http://gopalarathnam.com/weblog/
        Message 3 of 4 , Nov 2, 2007
        • 0 Attachment
          On Fri, Nov 02, 2007 at 01:33:44PM -0000, wizhippo wrote:
          > This is very frustrating.
          >
          >
          > How do I fire an onclick event from within javascript?
          >
          > I thought I should be able to do this but no.
          >
          > document.getElementById("test").onclick();
          >
          >

          document.getElementById("test").click();

          --
          Gopal Venkatesan

          http://gopalarathnam.com/weblog/
        • Kah Kah!
          wizhippo, thank you. I was really helped by your solution. And I modified yours a little to set the text-box object to fn s scope. var listeners =
          Message 4 of 4 , Mar 18, 2008
          • 0 Attachment
            wizhippo, thank you.
            I was really helped by your solution.
            And I modified yours a little to set the text-box object to fn's scope.

            var listeners = YAHOO.util.Event.getListeners(txtDate1,
            "change");
            for (var i=0; i<listeners.length; ++i) {
            var listener = listeners[i];
            - listener.fn(txtDate1);
            + listener.fn.call(txtDate1);
            }

            --- In ydn-javascript@yahoogroups.com, "wizhippo" <wizhippo@...> wrote:
            >
            >
            >
            > I want to fire the event listers for a an onChange event on a textbox
            >
            > so i have
            >
            > YAHOO.util.Event.addListener("check-in", "change",
            > YAHOO.tocom.quickSearch.validateDates);
            >
            > in another event i change the value of the text box but the onchange
            > does not get fired.
            >
            > var txtDate1 = document.getElementById("check-out");
            >
            txtDate1.value = month + "/" + day + "/" + year;
            >
            > This does not fire the onchange event.
            >
            > Do I have to do this to call all the eventlistners attached to the
            > element?
            >
            >
            var listeners = YAHOO.util.Event.getListeners(txtDate1,
            > "change");
            >
            for (var i=0; i<listeners.length; ++i) {
            >
            var listener = listeners[i];
            >
            listener.fn(txtDate1);
            >
            }
            >
            >
            >
            > or is there a simpler way?
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.