I’m using the Jquery multiselect checkbox plugin and am getting an error when converting the returned (CSV) values into an array. While this is not, strictly, a jQuery question it seems to throw an error on a standard js method.
Heres what I have:
$(function(){
$("select").multiselect({
click: function(e){
if( $(this).multiselect("widget").find("input:checked").length > 4 ){
return false;
}
},
close:function(evt, ui) { // Get the selected values upon close
var which = $(this).attr('id'); // Find out which selectbox was open
var checkedVals = $('#'+which).val(); // Get CSV string of checked options
var valArray = checkedVals.split(','); // convert CSV string to array
for(a in valArray) {
currentBox = ('#'+which+'Box'); // Find current selectbox wrapper
var eHeight;
eHeight = $('p'+currentBox).height(); // Current wrapper height
$('p'+currentBox).height(eHeight+18); // Add 18px to current wrapper for each Value
$('p'+currentBox).append('<div style="line-height:18px; margin-left:90px;"><a href="#"><img class="deleteVal" src="images/closewin.png" align="texttop" border="0"></a> '+valArray[a]+'</div>');
}
}
}).multiselectfilter();
I get back a comma separated string which I want to put into an array using js.
The error – “checkedVals.split is not a function” – is thrown at this line:
var valArray = checkedVals.split(‘,’);
You have to do 2 things
Make sure you have set
multipleproperty in html<select id="select" multiple="multiple">No need to convert to array.
valwill give the array ( NOT CSV ) of selected option values.var valArray = $('#' + which).val();demo : http://jsfiddle.net/diode/32h2g/3/