Page 1 of 1

how to retain list value on form

Posted: Mon Sep 21, 2009 11:02 pm
by om.bitsian
Hi friends.....
i have some select box in my form like
<label>1. Sex</label>
<select name="sx">
<option value='M'>Male</option>
<option value='F' >Female</option>
</select>
<br><br>

when i select Female and suppose there is an error in Name field , at that time when page reloded it will again reset the selected value i.e Male will appear in form...
for name field i am using value="<?php if (isset($_POST['submit'])) echo $_POST['name']; ?>" in the input labe ...in same way is there any option for select box

thank you

Re: how to retain list value on form

Posted: Tue Sep 22, 2009 1:39 am
by pbs
Use select box like this.

Code: Select all

 
<select name="sx">
<option value='M' <?php if (trim($_POST["sx"]) == "M") echo " selected ";?> >Male</option>
<option value='F' <?php if (trim($_POST["sx"]) == "F") echo " selected ";?> >Female</option>
</select>
 

Re: how to retain list value on form

Posted: Tue Sep 22, 2009 1:44 am
by om.bitsian
thank you pbs .......its giving warning
Notice: undifined index :sx