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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.