How to get all checked checkbox value in JavaScript?17 Mar 2025 | 5 min read A checkbox is a selection box that allows the users to make the binary choice (true or false) by checking and unchecking it. Basically, a checkbox is an icon, which is frequently used in GUI forms and application to get one or more inputs from the user.
Remember that checkbox is different from the radio button and dropdown list because it allows multiple selections at once. In contrast, the radio button and dropdown allow us to choose only one from the given options. In this chapter, now we will see how to get all marked checkbox value using JavaScript. Create checkbox syntaxTo create a checkbox use HTML <input> tab and type="checkbox" inside the tab as shown below - Although you can also create a checkbox by creating the checkbox object through JavaScript, but this method is a bit complicated. We will discuss both approaches later- ExamplesCreate and get checkbox valueIn this example, we will create two checkboxes but with the condition that the user will have to mark only one checkbox between them. Then we will fetch the value of the marked checkbox. See the code below: Copy Code Output If you mark the Yes checkbox and then click on the Submit button, a message will display as shown below: ![]() If you click on the Submit button without marking any of the checkboxes, an error message will be displayed. ![]() Similarly, you can check the output for other conditions. Get all checkbox valueNow, you will see how to get all checkbox values marked by the user. See the below example. Copy Code Output By executing this code, we will get a response like the below screenshot having some programming languages where you can choose the language you know. ![]() Here, you click on the Check all button, it will mark all the programming language checkboxes. After that, click on the Submit button to get the response. ![]() Although you can select the language one by one by marking an individual checkbox and then click on the Submit button to get the result. ![]() Output: When you have not selected anything ![]() Get all marked checkboxes value using querySelectorAll() methodThere is one more method to get all selected values from the checkboxes marked by the user. You will now see how to get the value of all checkboxes using the querySelectorAll() method marked by the user. This will fetch the checkboxes values from the HTML form and display the result. Get all checkbox valueNow, you will see how to get all checkbox values marked by the user. See the below example. Copy Code Output Here, you can see that all marked checkboxes value has been returned. ![]() Different JavaScript codes to get marked checkboxes valueJavaScript Code to get all checked checkbox values You can also use the below code to get all checked checkboxes values. So, checkbox elements allow to multi-select. This means that the users can select one or more options of their choice defined in the HTML form. Even you can select all the checkboxes. In the above example, you have already seen that. Next TopicHow to open JSON file |
Javascript logical assignment operators help to use the logical operators with the default and another expression. It works between two expressions or values with a single operator. ES2021 provides three logical assignment operators, which are as follows: Logical AND assignment operator Logical OR assignment operator Nullish coalescing assignment...
5 min read
The JavaScript textContent property works to set and get the page's text content. It is used to pass and display the text content of some information, tags, and large size of data and its nodes. The TextContent varies from the nodeValue of the script tag...
5 min read
Lookahead patterns enable JavaScript to move forward through the string to search for specified patterns. Lookaround is a combined expression of Lookahead and Lookbehind. We can only capture a specific group using lookaheads if they arrive before another group of characters. This is useful when...
4 min read
A bit-wise copy of an object is known as 'Shallow Copy'. When there is an original object, a new object is created where the same values as in the original object are copied. To know about Shallow copy, one should know about the types of data...
4 min read
Window.location is used to provide a Location object with details about the document's current location. This Location object reflects the location (URL) of the object it's linked to, i.e., it holds information about the current content location (host, href, etc.) JavaScript Location Object The window.location attribute represents...
8 min read
A parent node in JavaScript may have one or more child elements in JavaScript. Now how to fetch those child elements of a node in JavaScript is the question. In this section, we will discuss and look at how we can get child elements of a...
3 min read
The output of raising a first input value to the power of the second input value is returned by the exponentiation (**) operator. It is the same as Math.pow(), except that it also accepts BigInts as operands. The javascript exponentiation operator is used to calculate the...
5 min read
The JavaScript change event is an event type that gets executed when the focus on an element is changed. The change event of JavaScript inherits all the methods and properties of the Event. Here, in this section, we will understand and implement the practical use of...
5 min read
Front-End Developer: What is One? A front-end developer, usually referred to as a front-end web developer, is a specialist in charge of creating the interface. For them to use the application in question, the users need this interface. A web designer is a specialist who develops...
3 min read
Nowadays, almost all web-developers use JavaScript in their web-pages. JavaScript is a client-side scripting language that runs on a client machine (such as a web-browser). It helps web-developers to create modern web-pages that allow users to interact directly with the web-pages, without reloading them. If...
5 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India