0

I get a string like this from the my multi-select(link)

    assetmasterfields=$('#assetmaster').multipleSelect("getSelects");
var arr = assetmasterfields.split(',');
console.log(arr) 

This syntax gives me error:

'assetmasterfields.split is not a function'

I would like to turn this into a jQuery array. I have tried split couldn't get it right.

any ideas so that I can loop through the string as an array?

Thanks as always

Smudger
  • 9,873
  • 29
  • 100
  • 178
  • 1
    No jQuery required - use `split()`. Also note there is no such thing as a 'jQuery array'. – Rory McCrossan Jun 11 '15 at 10:33
  • You have to provide more details, like what plugin are you using, a sample of the output. If it's a string the below answer will work fine, if it's not a string you have to check the type of what's returned, maybe you can use something like `...multipleSelect('getSelects').each(.....)` – peppeocchi Jun 11 '15 at 10:47
  • thanks @peppeocchi, I am using this plugin:https://github.com/wenzhixin/multiple-select/tree/master/docs – Smudger Jun 11 '15 at 11:01

1 Answers1

1

Use following method to get the selected options as comma-separated text:

$('select').multipleSelect('getSelects', 'text');

To get selected option values as comma-separated string:

$("select").multipleSelect("getSelects");

Docs: http://wenzhixin.net.cn/p/multiple-select/docs/#methods

Tushar
  • 82,599
  • 19
  • 151
  • 169
  • Thanks, updated my question to be more accurate of my current situation, your example works perfectly but mine does not? issues with the way the string is generated from my multi select? – Smudger Jun 11 '15 at 10:40
  • @Smudger Check last edit in updated answer – Tushar Jun 11 '15 at 11:04