Prototype function to set onclick event observer in checkboxes

Posted by xain on Stack Overflow See other posts from Stack Overflow or by xain
Published on 2010-04-11T15:46:26Z Indexed on 2010/04/11 15:53 UTC
Read the original article Hit count: 231

Filed under:
|
|
|

Hi, I want to set an observer for each of the following checkboxes:

<div id="listr">
  <ul id="lr" style="list-style-type: none">
    <p class="tir">Text 1</p>
    <li class="ro"><input type="checkbox" name="r1" id="r1"/>A1</li>
    <li class="ro"><input type="checkbox" name="r2" />A2</li>
    <p class="tir">Text 2</p>
    <li class="rubro"><input type="checkbox" name="r3" />B1</li>
    <p class="tir">Text 3</p>
    <li class="ro"><input type="checkbox" name="r4" />B2</li>
  </ul>
</div>

It works if I write one observer per checkbox, but I want to do it in a short fashion, so I need something like

$$('listr.lr.li.input').invoke('observe',click,function(field) {
    alert(this.name + ' clicked ' + this.checked);
    // other stuff ...
});

Which is not working

Thanks in advance

© Stack Overflow or respective owner

Related posts about prototype

Related posts about checkbox