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

04-01-2007, 09: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

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

if ($checked === "employed")

04-01-2007, 10:50 PM
thank you

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


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

04-01-2007, 11:00 PM
one = assignment statement
two == comparison operator, same value
three === comparison operator, same value and same type

04-07-2007, 03: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,

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

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

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

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

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum