Skip to content
Advertisement

How get the value of multiple checkboxes in javascript

I used checkbox in two items now I can get the value of the second group of checkbox. The first group of checkbox I use:

<input name="option" type="checkbox" value="1" id="option1">option 1
<input name="option" type="checkbox" value="2" id="option2">option 2

Then

<input name="choice" type="checkbox" value="1" id="choice1">choice 1
<input name="choice" type="checkbox" value="2" id="choice2">choice 2

How can i get the value of selected checkboxes, in each group it is only allowed to select 1 checkbox.

I just need the javascript function

Answer

You can use this following codes to get the value of the checkbox if you are using multiple checkboxes.

$(‘input[name=option]:checked’).val();

Advertisement