{"id":1451,"date":"2016-07-10T01:15:36","date_gmt":"2016-07-10T01:15:36","guid":{"rendered":"http:\/\/javascript-tutor.net\/?p=1451"},"modified":"2016-07-25T03:35:41","modified_gmt":"2016-07-25T03:35:41","slug":"dealing-with-checkboxes","status":"publish","type":"post","link":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/10\/dealing-with-checkboxes\/","title":{"rendered":"Dealing with Checkboxes"},"content":{"rendered":"<p>Checkboxes are differently from radio buttons. While radio buttons only allow the user to select one option at a time, checkboxes allow the users to select multiple options. We can write a JavaScript function to verify which checkbox or boxes is\/are checked, as follows:<\/p>\n<p>function checkstatus()<\/p>\n<p>{var msg=&#8221; &#8220;;<br \/>\nfor(count=0;count&lt;4;count++)<br \/>\n{if (MyForm.MyCheckbox[count].checked)<br \/>\nmsg=msg+&#8221; &#8220;+MyForm.MyCheckbox[count].value;}<br \/>\ndocument.write(msg+&#8221; selected&#8221;);<br \/>\n}<\/p>\n<p>we shall call this function in an html document as follows:<\/p>\n<p>&lt;!doctype html&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;title&gt;Checkbox in JavaScript&lt;\/title&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n&lt;script type=&#8221;text\/javascript&#8221; src=&#8221;chkbox.js&#8221;&gt;&lt;\/script&gt;<br \/>\n&lt;form name=&#8221;MyForm&#8221;&gt;<br \/>\n&lt;input type=&#8221;button&#8221; value=&#8221;Click&#8221; onclick=&#8221;value=&#8221;Click&#8221; onclick=&#8221;checkstatus()&#8221;&gt;<br \/>\n&lt;input type=&#8221;checkbox&#8221; Name=&#8221;MyCheckbox&#8221; Value=&#8221;Item1&#8243;&gt;Item1&lt;br&gt;<br \/>\n&lt;input type=&#8221;checkbox&#8221; Name=&#8221;MyCheckbox&#8221; Value=&#8221;Item2&#8243;&gt;Item2&lt;br&gt;<br \/>\n&lt;input type=&#8221;checkbox&#8221; Name=&#8221;MyCheckbox&#8221; Value=&#8221;Item3&#8243;&gt;Item3&lt;br&gt;<br \/>\n&lt;input type=&#8221;checkbox&#8221; Name=&#8221;MyCheckbox&#8221; Value=&#8221;Item4&#8243;&gt;Item4&lt;br&gt;<\/p>\n<p>&lt;\/form&gt;<br \/>\n&lt;\/script&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<p>Click on <a href=\"http:\/\/javascript-tutor.net\/jSample\/chkbox.html\">Checkbox<\/a> to try it out.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Checkboxes are differently from radio buttons. While radio buttons only allow the user to select one option at a time, checkboxes allow the users to select multiple options. We can write a JavaScript function to verify which checkbox or boxes is\/are checked, as follows: function checkstatus() {var msg=&#8221; &#8220;; for(count=0;count&lt;4;count++) {if (MyForm.MyCheckbox[count].checked) msg=msg+&#8221; &#8220;+MyForm.MyCheckbox[count].value;} document.write(msg+&#8221; &hellip; <a href=\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/10\/dealing-with-checkboxes\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Dealing with Checkboxes&#8221;<\/span><\/a><\/p>\n","protected":false},"author":35895,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1451","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Dealing with Checkboxes - Learn JavaScript Online | Free Interactive JavaScript Tutorials<\/title>\n<meta name=\"description\" content=\"Learn how to manipulate check boxes in JavaScript\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/10\/dealing-with-checkboxes\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Dealing with Checkboxes - Learn JavaScript Online | Free Interactive JavaScript Tutorials\" \/>\n<meta property=\"og:description\" content=\"Learn how to manipulate check boxes in JavaScript\" \/>\n<meta property=\"og:url\" content=\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/10\/dealing-with-checkboxes\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn JavaScript Online | Free Interactive JavaScript Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-10T01:15:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-07-25T03:35:41+00:00\" \/>\n<meta name=\"author\" content=\"Liew Voon Kiong\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Liew Voon Kiong\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/10\/dealing-with-checkboxes\/\",\"url\":\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/10\/dealing-with-checkboxes\/\",\"name\":\"Dealing with Checkboxes - Learn JavaScript Online | Free Interactive JavaScript Tutorials\",\"isPartOf\":{\"@id\":\"https:\/\/javascript-tutor.net\/#website\"},\"datePublished\":\"2016-07-10T01:15:36+00:00\",\"dateModified\":\"2016-07-25T03:35:41+00:00\",\"author\":{\"@id\":\"https:\/\/javascript-tutor.net\/#\/schema\/person\/63d832c3efdf443517b5f5bfd1b93df8\"},\"description\":\"Learn how to manipulate check boxes in JavaScript\",\"breadcrumb\":{\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/10\/dealing-with-checkboxes\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/10\/dealing-with-checkboxes\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/10\/dealing-with-checkboxes\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/javascript-tutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Dealing with Checkboxes\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/javascript-tutor.net\/#website\",\"url\":\"https:\/\/javascript-tutor.net\/\",\"name\":\"Learn JavaScript Online | Free Interactive JavaScript Tutorials\",\"description\":\"Master JavaScript with free, interactive tutorials for beginners and experienced coders. Practice live coding and visualize how JavaScript works step by step.\",\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/javascript-tutor.net\/#\/schema\/person\/63d832c3efdf443517b5f5bfd1b93df8\",\"name\":\"Liew Voon Kiong\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/javascript-tutor.net\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/413ad70576fa5f43c1d3ae3429c92579c21f536c350e6470302fa25ddd9b6a13?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/413ad70576fa5f43c1d3ae3429c92579c21f536c350e6470302fa25ddd9b6a13?s=96&d=mm&r=g\",\"caption\":\"Liew Voon Kiong\"},\"url\":\"https:\/\/javascript-tutor.net\/index.php\/author\/ajt7051jct\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Dealing with Checkboxes - Learn JavaScript Online | Free Interactive JavaScript Tutorials","description":"Learn how to manipulate check boxes in JavaScript","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/10\/dealing-with-checkboxes\/","og_locale":"en_US","og_type":"article","og_title":"Dealing with Checkboxes - Learn JavaScript Online | Free Interactive JavaScript Tutorials","og_description":"Learn how to manipulate check boxes in JavaScript","og_url":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/10\/dealing-with-checkboxes\/","og_site_name":"Learn JavaScript Online | Free Interactive JavaScript Tutorials","article_published_time":"2016-07-10T01:15:36+00:00","article_modified_time":"2016-07-25T03:35:41+00:00","author":"Liew Voon Kiong","twitter_misc":{"Written by":"Liew Voon Kiong","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/10\/dealing-with-checkboxes\/","url":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/10\/dealing-with-checkboxes\/","name":"Dealing with Checkboxes - Learn JavaScript Online | Free Interactive JavaScript Tutorials","isPartOf":{"@id":"https:\/\/javascript-tutor.net\/#website"},"datePublished":"2016-07-10T01:15:36+00:00","dateModified":"2016-07-25T03:35:41+00:00","author":{"@id":"https:\/\/javascript-tutor.net\/#\/schema\/person\/63d832c3efdf443517b5f5bfd1b93df8"},"description":"Learn how to manipulate check boxes in JavaScript","breadcrumb":{"@id":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/10\/dealing-with-checkboxes\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/javascript-tutor.net\/index.php\/2016\/07\/10\/dealing-with-checkboxes\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/javascript-tutor.net\/index.php\/2016\/07\/10\/dealing-with-checkboxes\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/javascript-tutor.net\/"},{"@type":"ListItem","position":2,"name":"Dealing with Checkboxes"}]},{"@type":"WebSite","@id":"https:\/\/javascript-tutor.net\/#website","url":"https:\/\/javascript-tutor.net\/","name":"Learn JavaScript Online | Free Interactive JavaScript Tutorials","description":"Master JavaScript with free, interactive tutorials for beginners and experienced coders. Practice live coding and visualize how JavaScript works step by step.","inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/javascript-tutor.net\/#\/schema\/person\/63d832c3efdf443517b5f5bfd1b93df8","name":"Liew Voon Kiong","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/javascript-tutor.net\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/413ad70576fa5f43c1d3ae3429c92579c21f536c350e6470302fa25ddd9b6a13?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/413ad70576fa5f43c1d3ae3429c92579c21f536c350e6470302fa25ddd9b6a13?s=96&d=mm&r=g","caption":"Liew Voon Kiong"},"url":"https:\/\/javascript-tutor.net\/index.php\/author\/ajt7051jct\/"}]}},"_links":{"self":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/posts\/1451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/users\/35895"}],"replies":[{"embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/comments?post=1451"}],"version-history":[{"count":6,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/posts\/1451\/revisions"}],"predecessor-version":[{"id":1457,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/posts\/1451\/revisions\/1457"}],"wp:attachment":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=1451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=1451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=1451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}