Richard, Thank you Yuncong
On Feb 26, 11:34 am, Richard Quadling <rquadl...@googlemail.com> wrote: > 2009/2/26 Yuncong Zhang <njit...@gmail.com>: > > > > > > > I'm using prototype 1.5 > > > I want to click once and update text in two <div> parts. But I find > > out when I click the first time, nothing happened; when I click the > > second time, both div changed. why is that? > > > How can I click only once, change both of these <div>s. > > > Thank you in advance > > > Yuncong > > > <!-- code begins --> > > > <script language="javascript" src="prototype.js"></script> > > > <div id="qwer"> > > change this > > </div> > > > <div id="zxcv"> > > also change this > > </div> > > > <a id="asdf" onclick="new Event.observe('asdf', 'click', function(){ > > new Ajax.Updater > > ( > > 'qwer', > > 'event1.html', > > { > > asynchronous: true, > > method: 'get' > > } > > ); > > new Ajax.Updater > > ( > > 'zxcv', > > 'event2.html', > > { > > asynchronous: true, > > method: 'get' > > } > > ); > > }); > > event.returnvalue=false; > > return false; " > > href="event.html"> > > test > > </a> > > When you click the first time, it attaches an onclick event handler. > When you click the second time, the handler is executed. > > But potentially the handler could also be overwritten by attempting to > reattach the handler again. > > Much better is to put the onClick into... > > document.observe('dom:loaded', function() { > $('asdf').observe('click', function(ev) { > ev.stop(); > new Ajax.Updater( > 'qwer', > 'event1.html', > { > asynchronous: true, > method: 'get' > } > ); > new Ajax.Updater( > 'zxcv', > 'event2.html', > { > asynchronous: true, > method: 'get' > } > ); > }); > > }); > > sort of thing. > > The above code is probably only compatible with 1.6. I never used 1.5 sorry. > > -- > ----- > 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: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to prototype-core-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---