2009/1/15 geoffcox <g...@freeuk.com>: > > Hello, > > I have > > document.observe("dom:loaded", function () { > if ($("send1")) { > $("send1").observe("click", function (evt) { > evt.stop(); > getData(evt.element().form); > }); > } > }); > > in which the send1 is the id of the button in a form > > <input type="button" id="send1" value="Send"> > > If I have multiple forms how do I create general code to cope with say > 20 forms? > > The following loop idea does not work > > for (var count=1;count<21;count++) { > document.observe("dom:loaded", function () { > if ($("send" + count)) { > $("send" + count).observe("click", function (evt) { > evt.stop(); > getData(evt.element().form); > }); > } > }); > } > > Cheers, > > Geoff > > >
You could add the same class to each element and ... $$('.classname').invoke('observe', 'click', function(ev) { ... }); -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---