{"id":6813,"date":"2020-07-31T12:20:34","date_gmt":"2020-07-31T17:20:34","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=6813"},"modified":"2020-08-05T09:19:02","modified_gmt":"2020-08-05T14:19:02","slug":"html-checkbox-adding-and-removing-table-row","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=6813","title":{"rendered":"HTML Checkbox Adding and Removing Table Row"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Here&#8217;s the JavaScript code I ended up using to <a href=\"https:\/\/www.rushworth.us\/lisa\/?p=6808\" target=\"_blank\" rel=\"noreferrer noopener\">add and remove rows from a table based on a checkbox selection<\/a> (and only allowing one checkbox per group to be selected). The biggest change is that I added a name and ID to my TR for easier identification. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n$(document).on(&quot;change&quot;, &quot;input&#x5B;type=&#039;checkbox&#039;]&quot;, function () {\n    var $objCheckbox = $(this);\n    if ($objCheckbox.is(&quot;:checked&quot;)) {\t\t\t\/\/ When checked, deactivate other checkboxes and add to sets to create table\n        var objCheckboxGroup = &quot;input:checkbox&#x5B;tableselector=&#039;&quot; + $objCheckbox.attr(&quot;tableselector&quot;) + &quot;&#039;]&quot;;\n\n        $(objCheckboxGroup).prop(&quot;disabled&quot;, true);\n        $objCheckbox.prop(&quot;disabled&quot;, false);\t\t\/\/ Allow checked box to be unchecked\n\n        addSetToCreatingTable($objCheckbox.attr(&quot;setname&quot;), $objCheckbox.attr(&quot;settype&quot;), $objCheckbox.attr(&quot;goodcircuits&quot;) + &quot;|&quot; + $objCheckbox.attr(&quot;value&quot;), $objCheckbox.attr(&quot;tableselector&quot;));\n\n    }\n    else {\t\t\t\t\t\t\t\/\/ When unchecked, active checkboxes and remove from sets to create table\n        var objCheckboxGroup = &quot;input:checkbox&#x5B;name=&#039;&quot; + $objCheckbox.attr(&quot;name&quot;) + &quot;&#039;]&quot;;\n        $(objCheckboxGroup).prop(&quot;disabled&quot;, false);\t\n\n        $(&quot;#&quot; + $objCheckbox.attr(&#039;tableselector&#039;)).each(function(){ $(this).remove();})\n}\n});\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s the JavaScript code I ended up using to add and remove rows from a table based on a checkbox selection (and only allowing one checkbox per group to be selected). The biggest change is that I added a name and ID to my TR for easier identification.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[765,1037,856,854,1036,811],"class_list":["post-6813","post","type-post","status-publish","format-standard","hentry","category-coding","tag-html","tag-html-forms","tag-javascript","tag-jquery","tag-web-development","tag-web-programming"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/6813","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6813"}],"version-history":[{"count":2,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/6813\/revisions"}],"predecessor-version":[{"id":6838,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/6813\/revisions\/6838"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}