从一个下拉列表中选择一个选项填充其他输入字段 [英] Selecting an option from one drop down populates other input fields

查看:132
本文介绍了从一个下拉列表中选择一个选项填充其他输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在从下拉菜单中选择之后使用特定文本填充其他标记。



所以如果下拉和另一个下降到它下面应该发生。当你从dropDown1选择A时,dropDown2应填充你选择A。如果你选择BdropDown2应该说你选择B。 C也一样。



这里是下面的示例代码。

 < html> 
< body>
< form>

< select id =dropDown1>
< option value =A> A< / option>
< option value =B> B< / option>
< option value =C> C< / option>
< / select>

< select id =dropDown2>
< option value =您选择了A>您选择了A< / option>
< option value =您选择了B>您选择了B< / option>
< option value =您选择C>您选择了C< / option>
< / select>
< / form>

< / body>

< / html>

任何帮助将非常感谢。

解决方案

如果你能显示一些令人敬畏的代码,或者如果你能指出正确的方向, div>

对于像您所拥有的预定义值,您可以使用以下jQuery / JavaScript代码:

  $ (){
$('#dropDown1')。change(function(){
$('#dropDown2')。val('You chosen'+ this.value);
} );
});

JS Fiddle这里: http://jsfiddle.net/vleong2332/82w7p0a6/



下面是当dropDown2更改时更改dropDown1的示例。
http://jsfiddle.net/vleong2332/82w7p0a6/1/ p>

I am trying to figure out how to populate other tags with a specific text after selecting from a drop down.

So if the drop down and another drop down below it the following should happen. When you choose "A" from dropDown1, dropDown2 should populate with "You chose A". If you choose "B" dropDown2 should say "You chose B". Same goes for "C"

Here is a sample code below.

<html>
<body>
<form>

 <select id="dropDown1">
    <option value = "A">A</option>
    <option value = "B">B</option>
    <option value = "C">C</option>
 </select>

<select id="dropDown2">
    <option value="You chose A">You chose A</option>
    <option value="You chose B">You chose B</option>
    <option value="You chose C">You chose C</option>
</select>
</form>

</body>

</html>

Any help would be greatly appreciated. If you could show some code that be awesome or if you could point me in the right direction where I can find the answer that be awesome to.

解决方案

For predefined values like what you have, you can use the following jQuery/JavaScript code:

$(function() {
    $('#dropDown1').change(function(){
       $('#dropDown2').val('You chose ' + this.value);
    });
});

JS Fiddle here: http://jsfiddle.net/vleong2332/82w7p0a6/

Here is the example to change dropDown1 when dropDown2 changes. http://jsfiddle.net/vleong2332/82w7p0a6/1/

这篇关于从一个下拉列表中选择一个选项填充其他输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆