【问题标题】:Using a selection from a drop down list to show relevent information使用下拉列表中的选择来显示相关信息
【发布时间】:2014-07-11 23:22:03
【问题描述】:

To save space I need to add a drop down menu on my page that, when a location is selected, the address of that location is displayed in a field next to the drop-down menu.他们可以重复使用该下拉菜单来获取地址,而我不必将它们全部列出。我一直在寻找一个教程,该教程将展示如何在没有运气的情况下执行此类操作,这可能是因为我没有使用正确的术语进行搜索。

我之前以某种方式做过类似的事情,但我正在用所选文本填充表单中的另一个字段。有了这个,我需要填充分配给该位置名称的地址。

很抱歉,如果这里之前已经介绍过,任何帮助将不胜感激...是否有任何教程可以说明如何进行此操作?位置不多,所以如果有一种简单的方法可以做到这一点而不必求助于数据库等,那将是理想的。

谢谢

【问题讨论】:

标签: jquery html


【解决方案1】:

这是一个例子。将地址作为值放入,将位置作为选项文本放入。

<html>
<body>
<select id="location" name="location">
    <option value="dfsdfsdf">test</option>
    <option value="sdfsdfsdfsd">test2</option>
    <!-- Add more options -->
</select>
<input type="text" id="address" name="address" />
<script type="text/javascript">
    window.onload = function(){
        var location = document.getElementById("location");
        location.addEventListener('change',function(){
            document.getElementById("address").value = location.options[location.selectedIndex].value;
        });
    }
</script>
</body>
</html>

【讨论】:

  • 这正是我所需要的...非常感谢。
  • 有没有办法做这种确切类型的事情,但将地址文本加载到 DIV 中,我可以更好地控制格式(不是滚动条以及控制颜色和字体的能力)
  • 您可以将它移动到您想要的任何容器中。将输入更改为 div 并分配 innerHTML 而不是值。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-05-20
  • 2015-02-18
  • 1970-01-01
  • 2013-02-25
  • 2012-11-15
  • 1970-01-01
  • 2019-02-26
相关资源
最近更新 更多