JS Question: How to include a parameter when assigning a function to an event.
I have this code that is assigning a JS function to the onClick events of elements. container.childNodes[i].onclick = openClose; I would like to assign parameters so that the openClose function of different elements function on specific items. I recoginize that this syntax is not going to work: container.childNodes[i].onclick = openClose(paramA,paramB); But my Google searching skills are failing me on finding how one would do this type task, but surely it has got to be possible. I just can't imagine that it is not possible to define a function for an event handler that can not use parameters. ~| Want to reach the ColdFusion community with something they want? Let them know on the House of Fusion mailing lists Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:323642 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: JS Question: How to include a parameter when assigning a function to an event.
I finally found the right combination of Google Search terms and following other links to find at least one solution: container.childNodes[i].onclick = function() {openClose('hello world')}; I would be interesting in hearing if there are other solutions or any difficulties I might have with this version. TIA Ian ~| Want to reach the ColdFusion community with something they want? Let them know on the House of Fusion mailing lists Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:323645 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: JS Question: How to include a parameter when assigning a function to an event.
Other solutions? Use JQuery or Ext Core for this type of binding. Makes it very simple, and avoids any cross browser issues. Steve Cutter Blades Adobe Certified Professional Advanced Macromedia ColdFusion MX 7 Developer Co-Author of Learning Ext JS http://www.packtpub.com/learning-ext-js/book _ http://blog.cutterscrossing.com On 6/18/2009 10:51 AM, Ian Skinner wrote: I finally found the right combination of Google Search terms and following other links to find at least one solution: container.childNodes[i].onclick = function() {openClose('hello world')}; I would be interesting in hearing if there are other solutions or any difficulties I might have with this version. TIA Ian ~| Want to reach the ColdFusion community with something they want? Let them know on the House of Fusion mailing lists Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:323648 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: JS Question: How to include a parameter when assigning a function to an event.
Use JQuery and then check out the documentation on binding an event. A classic example is passing the id to a function to identify that element inside of the function: $(#TheButton).bind(click,function(el){openClose( $(this).attr(id) )}); function openClose(el){ if($(el).is(.closed)){ $(el).show(); $(el).addClass(open); } if($(el).is(.open){ $(el).hide(); $(el).addClass(closed); } } Make sense? ~| Want to reach the ColdFusion community with something they want? Let them know on the House of Fusion mailing lists Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:323650 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4