{"id":1213,"date":"2012-09-18T05:09:30","date_gmt":"2012-09-18T05:09:30","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=1213"},"modified":"2012-09-18T05:09:30","modified_gmt":"2012-09-18T05:09:30","slug":"jquery-comma-separated-list-of-labels-for-checked-checkboxes","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/jquery-comma-separated-list-of-labels-for-checked-checkboxes\/","title":{"rendered":"jQuery Comma Separated List Of Labels for Checked Checkboxes"},"content":{"rendered":"<p>If you have read my previous article on\u00a0how to make \u00a0<a title=\"jQuery Comma Separated List |Make Comma Separated List of Array values\" href=\"https:\/\/theextremewebdesigns.com\/blog\/jquery-comma-separated-list-make-comma-separated-list-of-array-values\/\" target=\"_blank\">jQuery Comma Separated List\u00a0of values<\/a>, then this article would be of interest to you. In this article, I am going to share a solution to\u00a0<strong><em>very easily make comma separated list of labels for checked checkboxes using jQuery<\/em>.<\/strong> Read on to find out more.<\/p>\n<p><!--more--><\/p>\n<h2>Examples to Get Comma Separated List of Labels\u00a0for\u00a0Checked Checkboxes using jQuery<\/h2>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=1213\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<p>Using\u00a0<strong>jQuery Comma Separated List Of Labels for Checked Checkboxes<\/strong> can be made very easily.\u00a0Let&#8217;s consider this with an example. Assume that we have set of checkboxes (array). Now we wish to use jQuery to make comma\u00a0separated\u00a0list from the labels of the\u00a0checked checkboxes. For this,<strong> it is mandatory to have labels for each of the checkboxes and the labels should point out to the ID of the respective checkbox<\/strong>.<\/p>\n<h3>Example: Here is the full source code to get\u00a0comma separated list of labels using jQuery<\/h3>\n<pre class=\"lang:xhtml decode:true\">&lt;html&gt;\n&lt;head&gt;\n&lt;title&gt;jQuery Comma Separated List |Make Comma Separated List of Array values&lt;\/title&gt;\n&lt;script type=\"text\/javascript\" src=\"js\/jquery-1.8.2.min.js\"&gt;&lt;\/script&gt;\n&lt;\/head&gt;\n\n&lt;body&gt;\n&lt;p&gt;\n\t&lt;label for=\"fruits_0\"&gt;\n\t\t&lt;input type=\"checkbox\" name=\"fruits[]\" class=\"fruits\" value=\"apple\" id=\"fruits_0\"&gt;\n\t\tApple&lt;\/label&gt;\n\t&lt;br&gt;\n\t&lt;label for=\"fruits_1\"&gt;\n\t\t&lt;input type=\"checkbox\" name=\"fruits[]\" class=\"fruits\" value=\"mango\" id=\"fruits_1\"&gt;\n\t\tMango&lt;\/label&gt;\n\t&lt;br&gt;\n\t&lt;label for=\"fruits_2\"&gt;\n\t\t&lt;input type=\"checkbox\" name=\"fruits[]\" class=\"fruits\" value=\"grapes\" id=\"fruits_2\"&gt;\n\t\tGrapes&lt;\/label&gt;\n\t&lt;br&gt;\n&lt;\/p&gt;\n\n&lt;input type=\"submit\" name=\"btn_alert\" id=\"btn_alert\" value=\"Alert Comma Seprated List\" \/&gt;\n\n&lt;script type=\"text\/javascript\"&gt;\n\n$(document).ready(function() {\n\n\t$('#btn_alert').click(function(){\n\n\t\tvar comma_separated_list = $(\".fruits:checked\").map(function() {\n\t\t\t\t\t\t\t\t\t\treturn $(this).val();\n\t\t\t\t\t\t\t\t\t\t}).get().join();\n\n\t\t\/\/Alert the VALUE of checked checkbox\t\t\t\t\t\n\t\talert(comma_separated_list);\n\n\t\tvar comma_separated_list_label = $(\".fruits:checked\").map(function() {\n\n\t\t\t\t\t\t\t\treturn $.trim( $(\"label[for='\"+$(this).attr(\"id\")+\"']\").text() );\n\n\t\t\t\t\t\t\t\t\t\t}).get().join();\n\n\t\t\/\/Alert the LABEL of checked checkbox\t\t\t\t\t\n\t\talert(comma_separated_list_label);\t\t\t\t\t\t\t\t\t\t\t\n\n\t\treturn false;\n\n\t});\t\t\n\n});\n\n&lt;\/script&gt; \n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p>Simply run the above code &amp; click on the button. That will give the\u00a0<strong>comma separated list of the checked\u00a0checkboxes\u00a0labels<\/strong>.<\/p>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=1213\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<h5>That&#8217;s it!<\/h5>\n<p>Do you know of any other ways to\u00a0<em><strong>make comma separated list of checked checkboxes labels using jQuery<\/strong><\/em>? Feel free to suggest by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have read my previous article on\u00a0how to make \u00a0jQuery Comma Separated List\u00a0of values, then this article would be of interest to you. In this article, I am going to share a solution to\u00a0very easily make comma separated list of labels for checked checkboxes using jQuery. Read on to find out more.<\/p>\n","protected":false},"author":1,"featured_media":395,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[20,13],"tags":[40,42,41],"class_list":["post-1213","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery-tips-and-tricks","category-tips-and-tricks","tag-jquery-2","tag-jquery-demos-2","tag-jquery-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-jz","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/1213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/comments?post=1213"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/1213\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/media?parent=1213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=1213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=1213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}