开发者

How to create comma seperated value in javascript on selection of values from multiple selection select box?

开发者 https://www.devze.com 2023-02-07 06:10 出处:网络
I need the values selected from multipleselect select box as commaseperated values so that I can use these values in AJAX call to fetch the data fro开发者_StackOverflow中文版m db table using these val

I need the values selected from multipleselect select box as commaseperated values so that I can use these values in AJAX call to fetch the data fro开发者_StackOverflow中文版m db table using these values.

Please help to me..

Thanks


Assuming multiSelect is the select DOM object (obtained by document.getElementById for instance), then resultString will be the string you are looking for.

 var resultArray = [];
 for(var i=0; i < multiSelect.options.length; i++) {
     if (multiSelect.options[i].selected) {
         resultArray.push(multiSelect.options[i].value);
     }
  }
  var resultString = resultArray.join(",");
0

精彩评论

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