By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,267 Members | 1,861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,267 IT Pros & Developers. It's quick & easy.

how to check if autogenerated checkbox is checked or not ?

P: n/a
Hello,
I have small script which generates some listboxes. Their names are
listXX (list01, list02, list03....). How to check if there are checked
or not ? If I have 1 listbox and have it's name I do $_POST['list01'].
But what to do in that situation ?

Sincerely,
Dmitrij

Oct 12 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I am sorry for my mistake. I mean check box and not $_POST... but
$list01 = "on"

:)

Oct 12 '07 #2

P: n/a

<dk*******@gmail.comwrote in message
news:11*********************@v23g2000prn.googlegro ups.com...
Hello,
I have small script which generates some listboxes. Their names are
listXX (list01, list02, list03....). How to check if there are checked
or not ? If I have 1 listbox and have it's name I do $_POST['list01'].
But what to do in that situation ?
lol. you bend over and take it like a man! you CANNOT CHECK a SELECT. ;^)

there are two ways to do this...correctly, or stupidly. sorry to say, but
you've started on a path that heads down the wrong road. make your inputs
arrays:

<input name='checkBox[meaningfulName1]' type='checkbox'>
<input name='checkBox[meaningfulName2]' type='checkbox'>

<?
$checkboxes = isset($_REQUEST['checkBox']) ? $_REQUEST['checkBox'] :
array();
foreach ($checkboxes as $meaningfulName =$value)
{
echo '<pre>' . $meaningfulName . '</pre>';
}
?>

the same goes for any other type of input including selects. the only
difference is that the only checkboxes that will be in $_REQUEST are those
that were actually checked...all other inputs will always be posted. i say
that in case you missed the 'foreach' rather than 'for'...since a specific
index number (like you were going for in your op) won't iterate as expected
when using the 'for' construct.

you could also use the 'while (list(' construct to make it more readily
apparent that $meaningulName is the only important thing about $checkboxes
rather than it's value. but i digress..
Oct 12 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.