Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox problem

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
US
Ok, so I have a form with lots of checkboxes, all the same name, and different values.

Here's a small sample for later clarity.

<input type = &quot;checkbox&quot; name=&quot;var_id&quot; value=7><b>BD2506</b> -- How blah<br>
<input type = &quot;checkbox&quot; name=&quot;var_id&quot; value=9><b>BD18</b> -- How blah2<br>
<input type = &quot;checkbox&quot; name=&quot;var_id&quot; value=11><b>BD16</b> -- What blah3<br>

Now, they're named the same thing for a good reason, they're all the same thing... and more importantly the form is dynamically generated, and dealing with it that way just makes more sense, assuming I can do what I want to do.

And that is simply, get the list of checked boxes... I could've sworn I did this, but now when I run my code it's not working. Is there an array or some value (I'm using POST but willing to use GET if need be) which is holding 7,9 & 11 when they're all checked? If I just try to use $HTTP_POST_VARS[&quot;var_id&quot;] I only get 11.

I thought I could set that to a variable say $temp, then count($temp) for the number of boxes checked, but that's not working... I figure if I need to do a workaround, I can have javascript tally up all the checked boxes and set a string equal to that list, but I'm preferring a direct approach to a workaround if one exists.

Thanks much,

-Rob
 
<input type = &quot;checkbox&quot; name=&quot;var_id[]&quot; value=7><b>BD2506</b> -- How blah<br>
<input type = &quot;checkbox&quot; name=&quot;var_id[]&quot; value=9><b>BD18</b> -- How blah2<br>
<input type = &quot;checkbox&quot; name=&quot;var_id[]&quot; value=11><b>BD16</b> -- What blah3<br>

add the [] to the name of the element to create the array, then just count the element in the array and do whatever you want with them

hth Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Jeesh I'm stupid, that is what I did, but later I saw those in there and axed them thinking, what in the world are they for when my PHP died on a parse error on that line for another reason... I proceeded to completely forget about them.

Thanks so much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top