How to use Checkbox inside Select Option using JavaScript ? Last Updated : 08 Jan, 2024 Comments Improve Suggest changes Like Article Like Report In this article, we are going to learn how to use Checkbox inside Select Option using JavaScript. ApproachThe HTML contains a styled dropdown (selectBox) and hidden checkboxes (checkBoxes).CSS styles enhance the appearance, styling the dropdown and checkboxes.The function showCheckboxes() toggles checkbox visibility on a dropdown click.Checkboxes are styled and change color on hover.Clicking the dropdown toggles checkbox visibility for user selections.Syntax:function showCheckboxes() { let checkboxes = document.getElementById("checkBoxes"); if (show) { checkboxes.style.display = "block"; show = false; } else { checkboxes.style.display = "none"; show = true; }}Example: In this example, we are following above explained approach. HTML <!DOCTYPE html> <html> <head> <title> How to use Checkbox inside Select Option using JavaScript? </title> <style> h1 { color: green; } .multipleSelection { width: 300px; background-color: #BCC2C1; } .selectBox { position: relative; } .selectBox select { width: 100%; font-weight: bold; } .overSelect { position: absolute; left: 0; right: 0; top: 0; bottom: 0; } #checkBoxes { display: none; border: 1px #8DF5E4 solid; } #checkBoxes label { display: block; } #checkBoxes label:hover { background-color: #4F615E; color: white; /* Added text color for better visibility */ } </style> </head> <body> <h1>GEEKSFORGEEKS</h1> <h2>Use CheckBox inside Select Option</h2> <form> <div class="multipleSelection"> <div class="selectBox" onclick="showCheckboxes()"> <select> <option>Select options</option> </select> <div class="overSelect"></div> </div> <div id="checkBoxes"> <label for="first"> <input type="checkbox" id="first" /> checkBox1 </label> <label for="second"> <input type="checkbox" id="second" /> checkBox2 </label> <label for="third"> <input type="checkbox" id="third" /> checkBox3 </label> <label for="fourth"> <input type="checkbox" id="fourth" /> checkBox4 </label> </div> </div> </form> <script> let show = true; function showCheckboxes() { let checkboxes = document.getElementById("checkBoxes"); if (show) { checkboxes.style.display = "block"; show = false; } else { checkboxes.style.display = "none"; show = true; } } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to use Checkbox inside Select Option using JavaScript ? K kumaravnish792 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How to Check/Uncheck the checkbox using JavaScript ? To check and uncheck the checkbox using JavaScript we can use the onclick event to toggle the checkbox value. We can also check or uncheck all the checkboxes on loading the webpage using JavaScript onload function.In this article, we will learn how to check/uncheck the checkbox using JavaScript. As 3 min read How to Create a Select All Checkbox in JavaScript ? In web apps with lots of checkboxes, a "Select All" checkbox is useful. It lets users check or uncheck all checkboxes at once, making things quicker. This feature can be implemented in various ways, such as utilizing JavaScript and JQuery to incorporate a "Select All" checkbox. This enhances the app 2 min read How to check whether a radio button is selected with JavaScript ? Here are the different methods used to check the radio button is selected:1. Using Input Radio checked propertyThe checked property in JavaScript checks if a radio button is selected. By using document.getElementById or querySelector to get the radio button, the checked property returns true if the 3 min read How to Get Selected Value in Dropdown List using JavaScript? A dropdown list is an HTML element that allows users to select one option from a list of options. The <select> and <option> tags are used to create dropdown lists in HTML. In this article, we will see how to get selected value from dropdown list using JavaScript.Basic HTML Structure for 2 min read How to select/deselect multiple options in dropdown using jQuery ? To select and deselect multiple options in a drop-down menu, we will use the HTML and CSS codes. HTML code helps to define the basic structure of the webpage and CSS will benefit in designing the web page. Some essential properties used in the code are as follows- <div> - This is a division ta 4 min read How to use javascript function in check box? Checkboxes are used for instances where a user may wish to select multiple options, such as in the instance of a "check all that apply" question, in forms. HTML Checkboxes Selected. A checkbox element can be placed onto a web page in a pre-checked fashion by setting the checked attribute with a "yes 2 min read How to get all checked values of checkbox in JavaScript ? A checkbox is a selection box that enables users to pick true or false in a binary manner by checking or unchecking it. When a checkbox is checked, it shows that the value has been chosen by the user, and when a checkbox is not checked indicates false which denotes that the user has not chosen the v 2 min read How to add options to a select element using jQuery? We will dynamically add the options to the select element using jQuery. jQuery has a lot of in-built methods. But, we will use some of them to accomplish the purpose of dynamically adding the options to the select element as listed below:Table of ContentBy passing the HTML of the option tag to the a 4 min read How to get all selected checkboxes in an array using jQuery ? In this article, we are going to discuss various methods to get all the selected checkboxes in an array using jQuery. Several ways of doing this in jQuery are explained in detail with their practical implementation using code examples. Table of Content Using the array.push() method with each() metho 4 min read How to create a Disabled Option Select using jQuery Mobile ? jQuery Mobile is a web-based technology used to make responsive content that can be accessed on all smartphones, tablets, and desktops. In this article, we will be creating a Disabled Option Select using jQuery Mobile. Approach: First, add jQuery Mobile scripts needed for your project. <link rel= 1 min read Like