7 Replies Latest reply on Jul 29, 2009 12:29 PM by jrble819

    Events not working



      I'm new to AIR HTML/Ajax development and right now I'm facing an issue related to events on elements inserted through Javascript in the DOM.


      I'm using Prototype.js as the development framework since that's what I'm most used to from regular web dev.

      When I do something like this, the onclick event never triggers.

      $('wrapper').insert({'top':'<input type="checkbox" name="" value="" onclick="testFunction()" />'});

      Any idea why?

      I noticed that the following works (but isn't viable for my uses):

      $('wrapper').insert({'top':'<input type="checkbox" name="" id="myCheckbox" value="" />'});


        • 1. Re: Events not working

          It's probably due to the sandbox. onClick="whatever()" is like an eval, which doesn't work after onload.


          Why won't the other form work? That's a better way of handling events anyway, it will give you cleaner and more managable code.

          1 person found this helpful
          • 2. Re: Events not working
            bbtti47 Level 1

            The other form (with Event.observe()) would mean a lot of extra code just to get a simple click event to work. Since the app runs with a lot of Ajax content, the elements get built dynamically.


            So, just to be sure, onclick() won't work on any code that is inject after the page has been loaded?

            Isn't there a way to have AIR to refresh all events on the page or anything like that?


            Thank you for your help!

            • 3. Re: Events not working
              evan64568745845674534 Level 1

              the way you're doing your events with the onclick="" attribute is seriously depricated anyway. Learn to do it another way.


              You could listen for click events on the "wrapper" element and then figure out which checkbox the click came from by interrogating the event object. Or you might find that you don't actually need to know which checkbox was clicked, but you can just get the value of all checkboxes at once and use that.

              • 4. Re: Events not working
                bbtti47 Level 1

                It's not really that simple, but thanks again.

                (deprecated or not, it works on all browsers and is much easier and faster -- of course AIR isn't a browser, but still…)

                • 5. Re: Events not working
                  evan64568745845674534 Level 1

                  Trust me, once you learn how to use events correctly, my way is faster and it will save you SO MUCH aggrevation.


                  By seperating your code out of your content you will save endless headaches.


                  I'd be happy to help you figure it out if you posted a larger example.

                  • 6. Re: Events not working
                    bbtti47 Level 1

                    Thank you for the help.

                    I'll let you know if I need help with the events handling.

                    • 7. Re: Events not working

                      I'm having the same problems.  I tried using the Event.observe() but it still isn't working right.  I am returning content from an Ajax.Updater and basically what is being returned is:


                      <a href="#" href="#" id="link_anID">http://google.com</a>
                         <script type="text/javascript"><!--
                      new Event.observe('link_anID','click',openInBrowser("http://google.com"));
                      // --></script>

                      I'm new to Air and mostly just playing around, but any help would be greatly appreciated.






                      Message was edited by: jrble819 -- I can't seem to get the insert RAW html feature to work correctly...