how to check if autogenerated checkbox is checked or not ?

how to check if autogenerated checkbox is checked or not ?

am 12.10.2007 23:21:20 von dkultasev

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

Re: how to check if autogenerated checkbox is checked or not ?

am 12.10.2007 23:32:29 von dkultasev

I am sorry for my mistake. I mean check box and not $_POST... but
$list01 = "on"

:)

Re: how to check if autogenerated checkbox is checked or not ?

am 12.10.2007 23:35:07 von Steve

wrote in message
news:1192224080.641241.93210@v23g2000prn.googlegroups.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:




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

' . $meaningfulName . '
';
}
?>

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..