I have a html select box with a list of countries. When I select one, it posts to the PHP method with no problem, but the select box resets to the top. How can I preserve th
Add the following to each OPTION. You will need to change this value for each.
<?php if($_POST['countryCd'] == '*this value*'){ php?>selected<?php } php?>
You may find this question useful:
Keep form values after submit PHP
Essentially you can use something like:
<select name="countryCD">
<option value="AFG"
<?php if(isset($_POST['countryCD']) && $_POST['countryCD'] == 'AFG')
echo 'selected= "selected"';
?>
>Afghanistan</option>
</select>
Try:
<select name="countryCd" onChange="submit();return false;">
<option value="AFG" <?= $_POST['countyCd'] == AFG ? 'selected' : '' ?>>Afghanistan</option>
<option value="ALA" <?= $_POST['countyCd'] == ALA ? 'selected' : '' ?>>Aland Islands</option>
<option value="ALB" <?= $_POST['countyCd'] == ALB ? 'selected' : '' ?>>Albania</option>
</select>