开发者

show multiple select box value with jquery?

开发者 https://www.devze.com 2023-01-02 11:47 出处:网络
i am a php developer and using an multiple select box , i want 开发者_运维百科when we select a multiple

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.

0

精彩评论

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