RE: [PHP-WIN] check boxes... set the VALUE or just echo CHECKED????
| From: | Gryffyn, Trevor | Date: | Tue, 06 Jul 2004 13:54:52 +0000 |
| Subject: | RE: [PHP-WIN] check boxes... set the VALUE or just echo CHECKED???? | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-24117@lists.php.net to get a copy of this message | ||
For HTML form elements that can be checked or selected or whatever, I
like to do something like this:
if ($conditionistru) { $checked = " CHECKED" } else { $checked = ""; }
echo "<input type=\"radio\" name=\"search\"
value=\"something\"$checked>";
If I was doing this for a combo/option box, I'd have a list of the
options in an array, use a "foreach" to create the <option> entries and
check the value from the array against the currently used value and
assign $checked = " CHECKED" if they match. This way, the previously
selected option is always auto-selected in your web form.
Part of the reason I put the space inside the quotes with the CHECKED is
so the HTML that's output is nice and clean. Nothing like seeing a
blank space and wondering what got omitted.
I don't know if that's the proper way.. But I don't see anything wrong
with it stylistically and it works for me.. And seems to qualify for
'easy' in my book.
-TG
> -----Original Message-----
> From: Leo G. Divinagracia III [mailto:ldivinag@csuhayward.edu]
> Sent: Monday, July 05, 2004 4:21 AM
> To: [PHP-WIN]
> Subject: [PHP-WIN] check boxes... set the VALUE or just echo
> CHECKED????
>
>
> i'm thinking of just adding the CHECKED word to the ECHO'ed HTML
> statement instead of dealing with the VALUE.
>
> what's the "proper" vs the "easy" way?
>
> thanks... i googled a few pages and it really didnt give a
> good result.
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>