doushizhou4477 2015-03-25 07:46
浏览 7

从选择列表中设置所选值时出错

I have a HTML select list where one can chose an option.

<select name='price' id='price'>
<option value='' >Select....</option>
<option value='0-50,000' selected>0-50,000</option>
<option value='50,000-100,000'>50,000-100,000</option>
<option value='100,000-150,000'>100,000-150,000</option>
<option value='150,000-200,000'>150,000-200,000</option>
<option value='200,000 and above'>200,000 and above</option>
<option value='see all'>See All</option>
</select>

When this list is submitted via a HTML submit button, this list shows again in another page. Now, I want the option the user selected to be new selected value. I am doing this:

<select name='price' id='price'>
<option value='{$_POST['price']}'>{$_POST['price']}</option>
<option value='0-50,000'>0-50,000</option>
<option value='50,000-100,000'>50,000-100,000</option>
<option value='100,000-150,000'>100,000-150,000</option>
<option value='150,000-200,000'>150,000-200,000</option>
<option value='200,000 and above'>200,000 and above</option>
<option value='see all'>See All</option>
</select>

But values are appearing twice. The option the user selected is shown as the selected and still appears in the list. For example, we now have something like this:

0-50,000 (this is the selected value)

0-50,000

50,000-100,000

100,000-150,000

150,000-200,000

200,000 and above

How do I solve this?

  • 写回答

5条回答 默认 最新

  • dsigg21445 2015-03-25 07:53
    关注

    In other page, make sure the selected option has selected="selected"

    <select name='price' id='price'>\
    <option value='' >Select....</option>
    <option selected="selected" value='0-50,000'>0-50,000</option>
    <option value='50,000-100,000'>50,000-100,000</option>
    <option value='100,000-150,000'>100,000-150,000</option>
    <option value='150,000-200,000'>150,000-200,000</option>
    <option value='200,000 and above'>200,000 and above</option>
    <option value='see all'>See All</option>
    </select>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等