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
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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.