<select name="country" id="country">
    <option value="IN">India</option>
    <option value="PK">Pakistan</option>
    <option value="UK">United Kingdom</option>
    <option value="US">United State</option>
</select>

When a user selects a country and clicks submit php gets the value="" ie, country code instead of country name.

Recommended Answers

All 3 Replies

$('#country>option:selected").html()

Whenever any select input is submitted it will take it's value not label.

$countries = array('IN'=>'India','PK'=>'Pakistan',
                 'UK'=>'United Kingdom','US'=>'United States');

echo "<form action='actionpage.php' method='post'>\r\n";
echo "<select name='country'>\r\n";
foreach($countries as $k=>$v){
    echo "<option value='{$k}'>{$v}</option>\r\n";
}
echo "</select>\r\n";
echo "</form>\r\n";

actionpage.php

<?php
$countries = array('IN'=>'India','PK'=>'Pakistan',
                 'UK'=>'United Kingdom','US'=>'United States');
echo $countries[$_POST['country']];
?>

if you're going to use it on many pages id put the array in it's own file and include it

commented: very well described +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.