Here is the code i have written, Please do help me to solve this issue.
<select name="gender" id="gender">
<option value="M"<?php if(isset($_POST['gender'])=="M"){echo "selected='selected'";}?>>Male</option>
<option value="F"<?php if(isset($_POST['gender'])=="F"){echo "selected='selected'";}?>>Female</option>
<option value="O"<?php if(isset($_POST['gender'])=="O"){echo "selected='selected'";}?>>Other</option>
</select>
When i submit the form by selecting Male in dropdown list, it should keep the selected value till i change that in the next submission of form.
In the above code if i select the Male and submit the form, its showing me Others.
so please need a little help. Thanks in advance to those who would like to fix the issue.
Assuming you have this :
<select name="gender">
<option value="Male">Male</option>
<option value="Female">Female</option>
<option value="Other">Other</option>
</select>
Then in your submitted page, place that :
<select name="gender">
<option value="Male" <?php if ($_POST['gender'] == 'Male') echo 'selected="selected"'; ?> >Male</option>
<option value="Female" <?php if ($_POST['gender'] == 'Female') echo 'selected="selected"'; ?> >Female</option>
<option value="Other" <?php if ($_POST['gender'] == 'Other') echo 'selected="selected"'; ?> >Other</option>
</select>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With