Jump to content

Assign value from a drop down menu


RobertSubnet

Recommended Posts

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

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

 

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.