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:
$no2 = $_POST['vehicleStyle'];
echo $no2;
where vehicleStyle is the name.
this is my code
<select name="vehicleStyle">
<option value="2">Volvo</option>
<option value="3">Saab</option>
<option value="4">Fiat</option>
<option value="5">Audi</option>
</select>
If I add
$no2 = $_POST['vehicleStyle'];
echo $no2;
to my code, I get either 2,3,4 or 5 (whichever is selected). How can I echo the dropdown name, either volvo, saab , fiat or audi?
NOTE: i use this code
$no2 = $_POST['vehicleStyle'];
echo $no2;
to show the price of the car which i set in value, but also i need to echo the text to show the name of the car, how i can do that?
name;idand explode it on the back end, or pass the value as a json object.value='{"name": "Volvo","id":2}'), - M. Erikssonvalueof the option to the text, unless you need the numeric ID - Martin