RobertSubnet Posted November 9, 2007 Share Posted November 9, 2007 Greetings all. Hopefully this is an easy question... I am trying to assign a value to a PHP variable from a drop down menu. The default value is "no." However if "yes" is chosen, I want that to be assigned to $_POST['local_pickup'] Here is what I have so far: <select> <option class = "blue_standard">No</option> <option class = "blue_standard">Yes</option> <?php if ($_POST['local_pickup'] == 'yes') echo $_POST['local_pickup']; ?> </select> Can anyone suggest how to get the yes value assigned to the $_POST['local_pickup'] variable if "yes" is chosen. Thank you for your suggestions. ~Robert Link to comment https://forums.phpfreaks.com/topic/76604-assign-value-from-a-drop-down-menu/ Share on other sites More sharing options...
GingerRobot Posted November 9, 2007 Share Posted November 9, 2007 You need to set a value for each option and give the select tag a name: <?php if(isset($_POST['local_pickup']){//has the form been submitted? echo 'Local pickup: '.$_POST['local_pickup']; } ?> <select name="local_pickup"> <option class = "blue_standard" value="no">No</option> <option class = "blue_standard" value="yes">Yes</option> </select> Also, you don't really want to be echoing out the variable between your select tags Link to comment https://forums.phpfreaks.com/topic/76604-assign-value-from-a-drop-down-menu/#findComment-387997 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.