Posts

Showing posts with the label multiselect

Multiselect Magic

Image
Background: I had this clever multiselect control for listing items that the user could select many entries from at any given time. I even made it look cool by implementing the Bootstrap Multiselect Plugin by David Stutz. However, when it was time to fetch the values of selected elements, I thought of looping through the elements to pull their values into an array. This would be inefficient and consume a lot of overhead! Solution: Turns out simply calling the javascript val() function on a multiselect returns an array of all values selected! e.g $('#selProgrammes').val() could return ["1", "2", "4", "6"] for example. Isn't it cool!