On 8 April 2010 12:20, Richard Quadling <rquadl...@googlemail.com> wrote: > Hi. > > Brain has gone to sleep. > > I've got a form where I'd like to be able to allow some controls to be > disabled by a checkbox. > > Working code ... > > <script type="text/javascript"> > function handleHideClick(ev) > { > hideClick(ev.element()); > } > > function hideClick(el) > { > el.up('tr').select('input[type=text]') > .each > ( > function(el2) > { > el2.disabled = el.checked; > } > ); > } > > document.observe('dom:loaded', function(ev_dom_loaded) > { > $$('.dtl_Blank input[type=checkbox]').each(function (el) > { > hideClick($(el).observe('click', handleHideClick)); > }); > }); > </script> > > Is there a way to simplify this? > > I initially thought that Element.fire() would help, but that is for > custom events only. > > Essentially, whilst setting the click handler, I want to be able to > call the handler also. > > Regards, > > Richard. > -- > ----- > Richard Quadling > "Standing on the shoulders of some very clever giants!" > EE : http://www.experts-exchange.com/M_248814.html > EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp > Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 > ZOPA : http://uk.zopa.com/member/RQuadling >
Ha! Seems that [1] and [2] have it covered. OOI, the fireEvent code at the bottom of [1] (Post #9 by Rick), (cleaned up the quotes) ... function fireEvent(element,event){ if(document.createEvent){ // dispatch for firefox + others var evt = document.createEvent('HTMLEvents'); evt.initEvent(event, true, true ); // event type,bubbling,cancelable return !element.dispatchEvent(evt); } else { // dispatch for IE var evt = document.createEventObject(); return element.fireEvent('on' + event,evt) } } looks good and useful. Is there a way to get this tested across a wide range of browsers/os/etc.? Does Prototype have a test farm? Richard. [1] http://jehiah.cz/archive/firing-javascript-events-properly [2] http://lifescaler.com/2008/04/simulating-mouse-clicks-in-javascript/ -- ----- Richard Quadling "Standing on the shoulders of some very clever giants!" EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- 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-scriptacul...@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.