Could you possibly give each checkbox the same class?

<a id="eid_22" class="checkMe"/>
<a id="eid_23" class="checkMe"/>
<a id="eid_24" class="checkMe"/>

$(function(){
  $("input.checkMe).click(function(){
    if (this.checked) {
      $("#eventItems").text(/([0-9]+)$/.exec(this.id)[1]);
    } else {
      $("#eventItems").empty();
    }
  });
});

On 10/18/07, choffman <[EMAIL PROTECTED]> wrote:
>
> Hello,
> I have a form where the values are pulled from MySQL and looped
> through using PHP. The name and id values are create dynamically.
>
> For example HTML:
> Item A <input type="checkbox" name="event_id_22" id="eid_22" / >
> Item B <input type="checkbox" name="event_id_23" id="eid_23" / >
>
> For example PHP:
> Item A <input type="checkbox" name="event_id_$value" id="eid_$value" /
> >
> Item B <input type="checkbox" name="event_id_$value" id="eid_$value" /
> >
>
> I'm using jQuery to count the boxes that get checked.  How can I get
> jQuery to see my PHP variable so it can count the number of boxes that
> get checked?  Thoughts?
>
> $(document).ready(function() {
>         $("#eid_??").click(function() {
>                         if (this.checked == true) {
>                                 var event_id = $("#eid_??").length;
>                                 $("#eventItems").text(event_id);
>                         }
>
>                         if (this.checked == false) {
>                                 $("#eventItems").empty();
>                         }
>         });
> });
>
>

Reply via email to