Multiselect Magic



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!

Comments

Popular posts from this blog

Resize or Crop Image before Upload Using HTML5 File API

Exception from HRESULT: 0x80131040

Get Creative With Data Tables: Row Click Events