Echo Dropdown's Option Name Rather Than Its Value

how to display the selected value in dropdown in php
drop down list using for loop in php
php dropdown
echo selected option value php
php foreach array select option
drop down list in php form
php select option array
php get selected value from dropdown

I am attempting to echo the name of a selected dropdown rather than its value. I understand that echoing a dropdown's value can be achieved by implementing something such as:

$variable = $_POST['vehicleStyle'];
echo $variable;

where vehicleStyle is the <select> name.

However, I am not after the value I after the option's name.

Here is my PHP. I am extracting data from a XML Document where $k equals the option name and $v equals its value.


    $xml = file_get_contents('note.xml');
    $dom = new DOMDocument();

    <form action="additionalinfo.php" method=POST>

     <select name="vehicleStyle">
      <option selected="selected">Choose style</option>
        foreach ( $dom->getElementsByTagName('style') as $styletwo )   {
          $styleid = $styletwo->getAttribute("name");
          $styleData [$styleid]= $styletwo->getAttribute("id");;
        foreach ($styleData as $k=>$v){
    <option value='<?php echo $v;?>'><?php echo $k;?> </option>

   <button class="button">Submit</button>


This outputs a dropdown containing two values: 'Audi=>292015` and 'BMW=>292016'. If I add

$variable = $_POST['vehicleStyle'];
echo $variable;

to my code, I get either 292015 or 292016 (whichever is selected). How can I echo the dropdown name, either Audi or BMW?


How about...

<option value='<?php echo $v . '|' . $k;?>'><?php echo $k;?> </option>


$variable = $_POST['vehicleStyle'];
$variable = explode('|', $variable);

echo $variable[0];  //The "value"
echo $variable[1];  //The "text"

Might make some validation more difficult but it should get you what you need.

You need to give your dropdown a name: HTML: <li> <select name="uDraft"> <​option value="Draft Offense">Draft Offense</option> <option  Hi All, I'm trying to echo out a value that was inserted into my database with a drop down box. For example, when I click 'edit' for a row, I want that value to be the value pre-selected in the

Just change the value of the option to $k instead i.e.

<option value='<?php echo $k;?>'><?php echo $k;?> </option>

Let's look at a new input: a "select" box, also known as a "drop-down" or $_​POST['formCountries']; if(!isset($aCountries)) { echo("<p>You didn't select any  T his tool will let you easily create a drop-down menu. F ill in the fields below and let this page do the javascript programming for you. T he menu supports both MSIE3+ and NS3+ browsers. A nd on top of it all: It even works with frames! U se the example below to test it for yourself!

If you only need the text and not the number, then don't include the number as the value in the option.

<option><?php echo $k;?></option>

If you don't specify a value attribute, the text will be used as the value by default.

If you need to get both the text and the value, there are various suggestions for how to do that here.

How to populate dropdown list with array values in PHP. Topic: PHP / MySQL​Prev| <option value="<?php echo strtolower($item); ?>"><?php echo $item; ?>​  I have an edit section to edit a status and other various information. I want the Status to be a drop down and then echo back. When using the code it just echos undefined. The text boxes (which I haven't included) work fine so I presume it is just because its a drop down instead of text boxes. The echo is in the first line of the code:

Depending on your settings, drop-down menus can serve the same purpose as radio buttons (one selection only) or check boxes (multiple selections allowed). If you don’t want to simply drop in and immediately begin chatting, you can still perform a normal call and have the Echo ring first, requiring the person on the other end to answer. To do this, just say “Alexa, call Kitchen Echo”. At the end, whether it’s a drop in or a call, just say “Alexa, hang up” and the communication will end.

The reason your $item == $option condition is always failing is because of the way PHP compares floats! Try the following instead: echo  I need to echo the selected value first in a form when user wants to make an update. Echo selected value first. Ask Question Get selected value in dropdown

Description The Select field creates a drop-down list to select one or more choices from. <p>Color: <span class="color-<?php echo esc_attr($value); ?>  Head to the icon on the top left of the Alexa app and select it to drop down the Menu. Choose Device Settings from here, and select each of your Echo devices in turn.

  • I need the value to remain $v but I also want to pull the name $k
  • I need the text and the number.