i am a php developer and using an multiple select box , i want 开发者_运维百科when we select a multiple option from the select box then value of every select box should be display in text box how can i do this with the help of jquery please help if anybody have solution of this thank's
Try this
$('#multiSelect').change(function() {
$('#txtSelect').val($('#multiSelect').val());
});
Based off a hint from jMar's blog:
$("#multipleSelect").change(function() {
$("#textBox").val("");
$("#multipleSelect option:selected").each(function(i) {
if (i > 0)
$("#textBox").val($("#textBox").val() + ", " + $(this).text());
else
$("#textBox").val($(this).text());
});
});
If you don't need the commas/separators, it's actually just:
$("#multipleSelect").change(function() {
$("#textBox").val($("#multipleSelect option:selected").text());
});
Fiddle with it over at jsfiddle.
精彩评论