开发者

How to put values in textbox from listbox in jQuery MVC ASP.NET

I have one Listbox named "List1" and one button says "Append".

I have on textbox named "TextDescription".

I want to put the select values from the listbox to textbox on click of append button.

So can any开发者_如何学JAVAone tell me how to do this?


You could use the .val() function. So assuming you have a select with id="myselect" and a text input with id="mytext" you could do this:

var values = $('#myselect').val();
if (values != null) {
    // concatenate the selected values with , so that we can add them to the textbox
    $('#mytext').val(values.join(','));
}

And here's a live demo illustrating it in action.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜