将文本框中的选定值移动到dropdpwn


move selected values form textbox to dropdpwn

我需要的是:用户在文本框中插入一个电影标题,只要他/她单击"移动到选定列表"按钮,电影标题就会移动到下拉列表中(显示用户选择的电影标题),文本框就会被清除。

我搜索了很多,但我找到的都是相反的(在文本框中插入选定的下拉列表!这与我需要的相反)。

这是我尝试过但不起作用的(它适用于将下拉列表中的选定选项移动到另一个下拉列表中,但不适用于文本框:

<input class="autofill4" type="textbox" name= "q27[]" id="q" placeholder="Enter movie titles here" />
<input type="button" value="Add to selected list" id="btnMove"/>
<select id="selectedItems" name="selectedItems[]" multiple="multiple" width="200px" size="10px">
</select> 

$('#btnMove').on('click', function (d) {
       var selected = $("#q").val();
       if (selected.length == 0) {
            alert("Nothing to move.");
            e.preventDefault();
       }
       $('#selectedItems').append($(selected));
       $(selected).remove();
       d.preventDefault();
   });   

如有任何帮助,我们将不胜感激:)

使用jquery这样尝试。

$('#btnMove').click(function (e) {
       var selected = $("#q").val();
       if (selected.length == 0) {
            alert("Nothing to move.");
            e.preventDefault();
       } 
       else
            $("#selectedItems").append(new Option(selected));
}); 

希望这能奏效。