Forum Moderators: coopster
<option value="one" <?php echo (isset($_SESSION['sel']) && $_SESSION['sel'] == 'one') ? 'selected' : ''; ?>>One</option>
<option value="two" <?php echo (isset($_SESSION['sel']) && $_SESSION['sel'] == 'two') ? 'selected' : ''; ?>>Two</option>
etc....
This uses the ternary operator for brevity. Hope this helps.
Assuming you've gotten the value from the session back into variable $select, you would:
<select name="select">
<option value="1"<?php if($select == 1) echo " selected"; ?>>a</option>
<option value="2"<?php if($select == 2) echo " selected"; ?>>b</option>
<option value="3"<?php if($select == 3) echo " selected"; ?>>c</option>
</select>
Use the same method for check boxes and radio buttons.
<input type="checkbox" name="check" value="1"<?php if($check == 1) echo " checked"; ?>>
Yeesh I hit 'refresh' before posting and still get beaten ;)
"checkform.php"
<?php session_start();?>
¦
¦html header here
¦
<?php
if (isset($_POST['submit']))
{
$_SESSION['Variable']= $_POST['Variable'];
////validation & other code here...
}
else
{include("form.php");}
?>
"form.php"
///I do not have session start here becoz its already in checkform.php and variable seem to get transferred on back and forth submit form..so sessions are working fine
<SELECT NAME="Variable">
<OPTION VALUE="nothing1"<?php if($_SESSION[''] == nothing1){ echo "";} ?>></option> //////this line to get top selection empty
<OPTION VALUE="A"<?php if($_SESSION['Variable'] =="A"){ echo "A";} ?>>A</option>
<OPTION VALUE="B"<?php if($_SESSION['Variable'] =="B"){ echo "B";} ?>>B</option>
?>
if I echo Variable anywhere in page,its showing fine..but not inside the selection box..
what is it that i m missing ?
thanks in adv
I do not have session start here becozIf it's a different script, you need it.
<OPTION VALUE="nothing1"<?php if($_SESSION[''] == nothing1){ echo "";} ?>></option> //////this lineThis will never be true so you'll never get anything out of it.
<OPTION VALUE="A"<?php if($_SESSION['Variable'] =="A"){ echo "A";} ?>>A</option>This should be: