I’m unable to perform the desired event.
<?php
include_once 'includes/db.php';
$result = mysql_query('SELECT country,code FROM countries') or die(mysql_error());
echo '<select id="CountryCode">';
echo '<option value="Select">Select</option>';
while ($row = mysql_fetch_array($result))
{
echo '<option value=$row["country"]>'.$row['country'].'</option>';
}
echo '<option value="Other">Other</option>';
echo '</select>';
?>
<input id="country" type="hidden" value="IN"/>
<script>
$(function()
{
$('#CountryCode').val($('#country').val());
});
</script>
Everything works fine. But the desired item is not selected in the select box
You need to set the Attribute “selected” of the option to “selected”. Try this (untested):