选择下拉组合框并将所选值放入动态创建的表单字段中

时间:2019-06-04 12:13:29

标签: jquery

我有一个程序可以动态创建表单字段组。在这些组中有一个组合框。我只需要在创建的组中将选定的值放到创建的其他文本框之一(在此示例中为TEXTO)中。

在下面的代码中,所选值放置在创建的所有TEXTO字段中,而不仅仅是创建的一个

$("body").on("change",".elcombo",function() {  
    var y = $(this).find('option:selected').val();

    $('input[name="texto[]"]').val(y);
});


<div class="form-group fieldGroupCopy" style="display: none;">
    <div class="input-group">
        <input type="text" name="texto[]" class="form-control" placeholder="Enter text"/>
        <input type="text" name="email[]" class="form-control" placeholder="Enter email"/>

        <select name="opcionesmenu" id="opcionesmenu" class="form-control elcombo" size="1"  onchange="javascript:void(0)">
           <option value="value 1">text 1</option>
            <option value="value 2">text 2</option>
            <option value="value 3">text 3</option>
            <option value="value 4">text 4</option>
        </select>

        <div class="input-group-addon"> 
            <a href="javascript:void(0)" class="btn btn-danger remove"><span class="glyphicon glyphicon glyphicon-remove" aria-hidden="true"></span> Remove</a>
        </div>
    </div>
</div>

我不知道如何选择目标字段的索引

0 个答案:

没有答案
相关问题