Skip to content

Instantly share code, notes, and snippets.

@AntMooreWebDev
Forked from ashcdev/comma-snippet.js
Last active May 11, 2019 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AntMooreWebDev/2276fc0a9cbdfabc6e687bb6d07bfe80 to your computer and use it in GitHub Desktop.
Save AntMooreWebDev/2276fc0a9cbdfabc6e687bb6d07bfe80 to your computer and use it in GitHub Desktop.
Convert Checkboxes or Similar into Comma Separated list
var checkedVals = $('input[type=checkbox]:checked').map(function() {
return this.value;
}).get().join(",");
$(*TARGET*).val(checkedVals);
@AntMooreWebDev
Copy link
Author

I feel that moving the join to the checkedVals variable instantiation makes more sense in this concept. It keeps the setting of the value tidier and allows the computational code to be more contained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment