Adding to a HTML text field by clicking items in a multiple select box

后端 未结 4 461
[愿得一人]
[愿得一人] 2021-01-26 19:31

I\'m wondering if it is possible that when I click on an item in a multiple select box in HTML that it goes into another form box? Basically, when I click on something I want th

4条回答
  •  面向向阳花
    2021-01-26 19:48

    You can do this, it finds the selected options, creates an array of text, then adds it to the text input.

    $("select[name=tags]").change(function() {
        var arrSelected = $(this).find("option:selected").map(function() {
            return $(this).text();
        }).get();
    
        $("input[name=taginput]").val(arrSelected);
    });
    

    Demo: http://jsfiddle.net/SyAN6/

提交回复
热议问题