[jQuery] Re: PHP variable into jQuery

2007-10-19 Thread James Dempster
Try this.

$(document).ready(function() {
   $("input.checkme").click(function() {
   $('#eventItems').text(''+$('input.checkme:checkbox:checked'
).length);
   });
});


On 10/18/07, choffman <[EMAIL PROTECTED]> wrote:
>
>
> 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?
> >
> > 
> > 
> > 
> >
> > $(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 
> > > Item B 
> >
> > > For example PHP:
> > > Item A  >
> > > Item B  >
> > > 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();
> > > }
> > > });
> > > });
>
>
> >
>


-- 
/James


[jQuery] Re: PHP variable into jQuery

2007-10-18 Thread choffman

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?
>
> 
> 
> 
>
> $(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 
> > Item B 
>
> > For example PHP:
> > Item A 
> > Item B 
> > 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();
> > }
> > });
> > });



[jQuery] Re: PHP variable into jQuery

2007-10-18 Thread James Dempster

If all these checkboxes are in the same container where no other
checkboxes are you can use somthing like this
$('#id input:checkbox:checked').length

Or if there are other checkboxes in the way you can give all these
checkboxes the same class name and do
$('#id input.classname:checkbox:checked').length

Think these should both work, if I've understood what you are asking
for.

On Oct 18, 8:41 pm, 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 
> Item B 
>
> For example PHP:
> Item A 
> Item B 
>
>
> 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();
> }
> });
>
> });



[jQuery] Re: PHP variable into jQuery

2007-10-18 Thread Jake McGraw

Could you possibly give each checkbox the same class?





$(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 
> Item B 
>
> For example PHP:
> Item A  >
> Item B  >
>
> 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();
> }
> });
> });
>
>