Convert all checked checkboxes into an comma seperated string with JQuery

Sometimes i just love jQuery. Well most of the time actually. I did some work for a client a couple of week ago and i needed get all checkoboxes that was checked as a comma seperated list. I started with this code. I found out about the “map” method of jQuery wich has the following description.

Translate all items in an array to another array of items.

The translation function that is provided to this method is called for each item in the array and is passed two arguments: The the item to be translated, and index within the array.The function can then return the translated value, ‘null’ (to remove the item), or an array of values – which will be flattened into the full array.

The code i ended up with looked like this. Really really neat.






    
    

2 Responses to “Convert all checked checkboxes into an comma seperated string with JQuery”

  1. Very helpful, thanks for the code.

  2. [...] http://codepolice.net/2009/11/07/convert-all-checked-checkboxes-into-an-comma-seperated-string-with-... [...]

Leave a Reply