Using jQuery Multiselect plugin and need to check if any selections have been made (user may open and close select box without choosing anything). This plugin has a “close” method which I use to get the array of selected/checked options:
var checkedVals = [];
checkedVals = $('#'+which).val(); // Get Array of checked options
alert(checkedVals.length); // See if it's empty
When an option is selected/checked, it works fine (so I know I’m returning values) but when nothing is selected, Firebug throws an error stating that checkedVals is null. An empty array should be 0… not null. And pls… let’s not get into the discussion of trying to trap “null”.
Thanks for any help
Write it like this and you will always have an array
It will set checkedVals to the .val() value or to an empty array if it’s null (falsey).