Re: making checkbox's and radio buttons sticky

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ted Passey wrote:
Jochem,

Thanks for your help...I can see your a great PHP programmer.

flattery gets you everywhere - even if it isn't true.
I'm not that bad - but lets leave the 'great' for those that really are -
you know people who develop/invent the actual language - people who
write books about it, people like that :-)

oh and as long as it's php related make sure to atleast cc the list.


The dynamic checkbox code you sent worked great!
I am however have a problem with a set of radio buttons...

I am trying to appy the same principle here...
The problem I am encountering is the $checked value in the echo string will
always show
the button "checked" So no matter what is selected, it comes back to
"checked"

Any suggestions?

HTML is:

 <input name="member" type="radio" value="Yes" checked>  Member

I assume that should be?:

<input name="member" type="radio" value="Yes" checked="checked">  Member

 <input name="member" type="radio" value="No">Prospective Member

PHP is:
<?

if ($member) {

if $member containseither 'Yes' or 'No' then it will equate to boolean
true - which is what you are in fact testing

try something like:

if ($member == 'Yes') {

$checked = ' checked="checked"';
} else {
$checked = '';
}

echo '<input name="member" type="radio"',$checked,'/>';

?>

Thanks for the help...

zed

----- Original Message ----- From: "Jochem Maas" <jochem@xxxxxxxxxxxxx>
Newsgroups: php.general
To: "zedleon" <support@xxxxxxxxxxxxxx>
Cc: <php-general@xxxxxxxxxxxxx>
Sent: Thursday, August 11, 2005 9:18 PM
Subject: Re:  making checkbox's and radio buttons sticky



zedleon wrote:

I am new to php and am in need of some guidance
I am building a sticky form and am having trouble bringing in the data

sticky as in honey?


fields for
checkbox's and radio button's. Any help on how to do this would be
appreciated

HTML  form sample
<input name="gmev[]" type="checkbox" id="gmev" value="September

9th"></th>

PHP
<input name="gmev[]" type="checkbox" id="gmev" value="<? echo $gmev_day
?>"></th>

am I on the right track here?

maybe, partially - generally radio buttons and checkboxes have fixed

values -

it's the 'are they selected' part that probably want to make dynamic...
basically you need to conditionally add the attribute 'checked' (i.e.
checked="checked") to the radios and checkboxes you want selected when the
form is first shown.

e.g.

<?

if ($thisChkBoxIsInitiallySelected) {
$checked = ' checked="checked"';
} else {
$checked = '';
}

echo '<input name="gmev[]" type="checkbox" id="gmev"',$checked,'/>';

?>

of course there are a million different ways to write this kind of thing
(i.e. don't take my example verbatim perse) but hopefully you get the

idea.

zed




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux