[Proto-Scripty] Add event by class name
Hello I have a problem with adding event click to elements by class name. I'm trying to add event onclick to all input tags that have class compare_itm by this code: $$('input.compare_itm').observe('click', myFunction); But it doesn't work. Is it possible to do in Prototype ? thanks -- 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.
[Proto-Scripty] Re: Add event by class name
thanks, it works ! Another question: how can I send element as argument to the click function ? I'm trying to use this: $$('input.compare_itm').invoke('observe', 'click', myFunction.bindAsEventListener('compare', this )); function myFunction(group, elm){ alert(elm.value); // undefined } On Aug 23, 11:00 am, Johan Arensman johanm...@gmail.com wrote: You are trying to apply a single method to a set of items. For this to work you need to apply the same function to each member of the set using invoke(). $$('input.compare_itm').invoke('observe', 'click', myFunction); See also:http://api.prototypejs.org/language/enumerable/prototype/invoke/ Hope this helps! Greets, Johan On Mon, Aug 23, 2010 at 9:35 AM, elivol eli...@gmail.com wrote: Hello I have a problem with adding event click to elements by class name. I'm trying to add event onclick to all input tags that have class compare_itm by this code: $$('input.compare_itm').observe('click', myFunction); But it doesn't work. Is it possible to do in Prototype ? thanks -- 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.comprototype-scriptaculous%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- 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.
[Proto-Scripty] How to insert element with value taken from attribute of parent ?
Hello. I have this HTML code: div class=item_content sale_num=12345some stuff/div div class=item_content sale_num=123456some stuff/div I need to insert a checkbox into div item_content with value of sale_num attribute. I'm trying to do it with: $$('div.item_content').invoke('insert', {bottom: 'input type=checkbox class=compare_itm value= /' }); but i have no idea how to continue. thanks in advance. -- 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.
[Proto-Scripty] Re: How to insert element with value taken from attribute of parent ?
Hello Unfortunately it doesn't work: $$('div.item_content').invoke('insert', {bottom: 'input type=checkbox class=compare_itm onclick=Itm.Click(\''+ this.getAttribute('sale_num') +'\') /' }); The script fails if I put this.getAttribute('sale_num') On Aug 27, 6:55 pm, Walter Lee Davis wa...@wdstudio.com wrote: You could get the value inside your iterator by looking at: this.getAttribute('sale_num') Inside of an invoke iterator, 'this' is set to the current object of affection. Don't forget to give your generated checkbox an ID or name or something else based on this value you get, so your checkboxes will tell a story to your compare script! Walter On Aug 27, 2010, at 9:01 AM, elivol wrote: Hello. I have this HTML code: div class=item_content sale_num=12345some stuff/div div class=item_content sale_num=123456some stuff/div I need to insert a checkbox into div item_content with value of sale_num attribute. I'm trying to do it with: $$('div.item_content').invoke('insert', {bottom: 'input type=checkbox class=compare_itm value= /' }); but i have no idea how to continue. thanks in advance. -- 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 athttp://groups.google.com/group/prototype-scriptaculous?hl=en . -- 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.
[Proto-Scripty] Re: How to insert element with value taken from attribute of parent ?
thank you a very much for a detailed answer ! it works fine. On Aug 30, 12:31 am, T.J. Crowder t...@crowdersoftware.com wrote: Hi, You don't want #invoke, you want #each: $$('div.item_content').each(function(div) { div.insert({ bottom: 'input type=checkbox class=compare_itm onclick=Itm.Click(\''+ div.readAttribute('sale_num') +'\') /' }); }); http://api.prototypejs.org/language/enumerable/prototype/each/ Also note I've used #readAttribute (Prototype) rather than getAttribute (DOM), as it handles some issues for you: http://api.prototypejs.org/dom/element/readattribute/ Off-topic: That HTML is invalid, because you're defining an attribute (`sale_num`) that doesn't exist in the standard. It works, it's just invalid. As of HTML5, there's a valid way to have custom attributes: Use a data- prefix. So `data-sale_num` would be a valid attribute name. FWIW. HTH, -- T.J. Crowder Independent Software Consultant tj / crowder software / comwww.crowdersoftware.com On Aug 29, 8:47 am, elivol eli...@gmail.com wrote: Hello Unfortunately it doesn't work: $$('div.item_content').invoke('insert', {bottom: 'input type=checkbox class=compare_itm onclick=Itm.Click(\''+ this.getAttribute('sale_num') +'\') /' }); The script fails if I put this.getAttribute('sale_num') On Aug 27, 6:55 pm, Walter Lee Davis wa...@wdstudio.com wrote: You could get the value inside your iterator by looking at: this.getAttribute('sale_num') Inside of an invoke iterator, 'this' is set to the current object of affection. Don't forget to give your generated checkbox an ID or name or something else based on this value you get, so your checkboxes will tell a story to your compare script! Walter On Aug 27, 2010, at 9:01 AM, elivol wrote: Hello. I have this HTML code: div class=item_content sale_num=12345some stuff/div div class=item_content sale_num=123456some stuff/div I need to insert a checkbox into div item_content with value of sale_num attribute. I'm trying to do it with: $$('div.item_content').invoke('insert', {bottom: 'input type=checkbox class=compare_itm value= /' }); but i have no idea how to continue. thanks in advance. -- 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 athttp://groups.google.com/group/prototype-scriptaculous?hl=en . -- 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.