Jump to content

[SOLVED] Setting Selected option using PHP


AshmanSNET

Recommended Posts

Hi,

I have a drop down list which I want to be set to what was selected when the form is submitted. As the form is processed by the same page, it returns to the preset default. How would I go about making this selection box set the option selected on the next page?

 

Thanks

 

Ash

Link to comment
https://forums.phpfreaks.com/topic/72877-solved-setting-selected-option-using-php/
Share on other sites

<?php
echo '<select name="gender">';
echo '<option value="male"';
if (strtolower($_POST['gender']) == 'male') echo ' selected="selected"';
echo '>Female</option>';
echo '</select>';
echo '<input type="submit" value="Submit" name="submit"></td></tr>';
echo '</table>';
echo '</form>';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.