Giving the check boxes the same class helped. Thanks. I've only been using jQuery for a short time, I'm trying to learn the ins and outs of it.
I changed the code back to use length. Otherwise, I was just getting the value of the checkboxes. I would like to know how many boxes are checked and have it update itself when boxes are checked or unchecked. For example, if I have 6 checkboxes and 3 are checked the output should show 3. If I uncheck one it should 2 and vice versa. The result get sent to a div, in this case #eventItems. $(document).ready(function() { $("input.checkme").click(function() { if (this.checked == true) { var event_id = $("#eventItems").length; $("#eventItems").text(event_id) + 1; } else { $("#eventItems").empty(); } }); }); On Oct 18, 2:11 pm, "Jake McGraw" <[EMAIL PROTECTED]> wrote: > 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(); > > } > > }); > > });