PHP提交后保留选择选项 [英] Preserving a select option after PHP submit
本文介绍了PHP提交后保留选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有国家/地区列表的html选择框.当我选择一个时,它将毫无问题地发布到PHP方法,但是选择框重置为顶部.如何保存用户在此处选择的值?我的代码在这里(为简便起见,我已将其他大多数国家/地区排除在外)
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 the value that the user selected here? My code is here (for brevity's sake, I've taken out most of the other countries)
<html>
<body>
<form action="" method="post">
<select name="countryCd" onChange="submit();return false;">
<option value="AFG">Afghanistan</option>
<option value="ALA">Aland Islands</option>
<option value="ALB">Albania</option>
</select>
</form>
<?php echo $_POST["countryCd"]; ?>
</body>
</html>
推荐答案
您可能会发现此问题有用:
You may find this question useful:
基本上,您可以使用类似的东西:
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>
这篇关于PHP提交后保留选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文