...

View Full Version : selecting a radio button with a session variable



ClubCosmic
04-01-2007, 10:52 PM
This is my code:


$checked = $_SESSION['empstatus'];

echo '<p>Employed<input type="radio" name="empstatus" value="employed"'; if ($checked = "employed") { echo "SELECTED";} echo '>';
echo 'Unemployed<input type="radio" name="empstatus" value="unemployed"'; if ($checked = "unemployed") { echo "SELECTED";} echo '>';
echo 'Retired<input type="radio" name="empstatus" value="retired"'; if ($checked = "retired") { echo "SELECTED";} echo '>';
echo 'Disabled<input type="radio" name="empstatus" value="disabled"'; if ($checked = "disabled") { echo "SELECTED";} echo '>';

it does not give me the session variable as being the selection checked, and i can echo the variable

any help thanx in advance
c.c.

mlseim
04-01-2007, 11:01 PM
Change the equal signs in your "if" statements ...

if ($checked === "employed")

ClubCosmic
04-01-2007, 11:50 PM
thank you

that means "is equal to and of the same type"

correct?

also,
is the rest of the statement ok? (echo"SELECTED")

CFMaBiSmAd
04-02-2007, 12:00 AM
one = assignment statement
two == comparison operator, same value
three === comparison operator, same value and same type

ClubCosmic
04-07-2007, 04:16 PM
Hi all,

This is a question that im posting again because i cant get it to work.

Basically i have a form field using radio buttons. When submitted, it places the value in a session. I am trying to display the session value as SELECTED when I redisplay the form. instead it comes up blank.

My question is can anyone look at the code and tell me if i am even doing this correctly. Maybe i should use a dropdown list but i would rather not.

thankx again,
c.c.

CFMaBiSmAd
04-07-2007, 04:40 PM
Syntax for a "checked" radio button -

<input type="radio" name="somename" value="somevalue" checked="checked">

ClubCosmic
04-07-2007, 05:04 PM
thanks again!!

awsomejoe23
04-07-2007, 06:18 PM
DELETE: Sorry wrong post.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum