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 |
In this article, we are going to discuss about the formatting of numbers with commas in JavaScript. Sometimes, we require formatting a number with commas in the HTML page in order to make it easy to read. Using JavaScript, we can transform a number into...
4 min read
iousElementSibling Property in javascript The javascript iousElementSibling Property works to display the ious node of the required or input node as a Node object. If the given node is the initial element of the list, then the nodes object displays null. The iousElementSibling Property is used to...
3 min read
Difference between entDefault() and stopPropagation() methods In this post, we will cover the entDefault & stopPropagation methods with appropriate code examples for each condition, and then we will see how they differ. We can utilize the entDefault() and stopPropagation() functions in jQuery event handler functions. The entDefault() stops...
4 min read
The () is a method that is used for inserting a child node before another node of a specified parent node. In this section, we will learn about the insertBefore () method and look at an example to understand the implementation of the insertBefore ()...
3 min read
A 2D drawing context's translate() method is used. The canvas and its origin are moved by x and y units using the translate(x,y) method. Otherhand, The drawing position (0,0) on the canvas is remapped by the translate() method. The value is included in the x- and...
6 min read
? A radio button is an icon that is used in forms to take input from the user. It allows the users to choose one value from the group of radio buttons. Radio buttons are basically used for the single selection from multiple ones, which is...
8 min read
How to make a curved active tab in the navigation menu using HTML CSS & JavaScript? In this article, we will learn how to make curved outside in active tab in navigation menu using HTML, CSS & JavaScript. We use the HTML list element to create...
10 min read
JavaScript allows us to add special characters to a text String using a backslash (\) sign. We can add different types of special characters, including the single quote, double quote, ampersand, new line, tab, backspace, form feed, etc., using the backslash just before the characters. The...
2 min read
Text to Particles Dissolve Effect JavaScript & CSS In this article, we will understand how to create example of text to particles dissolve effect by using JavaScript & CSS. Particles dissolve effect is used for creating animated, interactive, configurable particle animations on a Canvas element that...
6 min read
? If you are a Smartphone user, it is quite possible that your Smartphone may work on Android OS. However, if your phone's browser is configured to disable JavaScript, you will certainly experience an unsatisfactory web browsing. So, it is necessary to use the web browser...
2 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