Re: checking if checkbox is checked
| From: | Steve Werby | Date: | Wed, 04 Jul 2001 23:29:07 +0000 |
| Subject: | Re: checking if checkbox is checked | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-56243@lists.php.net to get a copy of this message | ||
"Richard Kurth" <rkurth@pacifier.com> wrote:
> I have 5 checkbox's in a form that I what to make sure at least one of
> the checkbox is checked.
>
> <input type='checkbox' name='interest' value='basic'>
> <input type='checkbox' name='interest3' value='Internet access
> '>
> <input type='checkbox' name='interest1' value='pro'>
> <input type='checkbox' name='interest4' value='domain
> name'>
> <input type='checkbox' name='interest2' value='platinum'>
if ( $interest == 'basic' || $interest3 == 'Internet access' || ...
$interest2 == 'platinum' )
{
echo "At least one was checked.";
}
Ignoring the first input box you could also use a loop since the field names
are sequential. You could also handle the first field, by starting $i at 0
and only appending $i if it's greater than 0, but I don't want to clutter
the code. The code below assumes the fields aren't preset to values other
than those listed above.
for ( $i = 1; $i < 4; $i++ )
{
$field = 'interest' . $i;
if ( ! empty( $$field ) )
{
$flag = TRUE;
}
}
if ( $flag == TRUE )
{
echo "At least one was checked.";
}
--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/