how to get all radio button value by name

Kelpie

Like the title say i want to get all the radio button value that using the same name. here is the html code

<input type="radio" id="choice-yes-1" name="choice[0]" value="Yes" /> Yes <br/>
<input type="radio" id="choice-no-1" name="choice[0]" value="No" /> No <br />
<input type="radio" id="choice-yes-2" name="choice[1]" value="Yes" /> Yes <br />
<input type="radio" id="choice-no-2" name="choice[1]" value="No" /> No <br />

i want the javascript kinda like this

ctr = 0;
for (i=0;i<2;i++){
    if(document.getElementsByName("choice")[i].value == "Yes"){
        ctr++;
    }
}
console.log(ctr);

i want some javascript that kinda resulting how many the yes choice.

Carsten Løvbo Andersen

You can use $('input[id^=choice-][value=Yes]:checked').length to get all checked elements with the value of Yes

$('input[id^=choice-][type=radio]').change(function() {
  console.log($('input[id^=choice-][value=Yes]:checked').length)
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="radio" id="choice-yes-1" name="choice[0]" value="Yes" checked /> Yes <br/>
<input type="radio" id="choice-no-1" name="choice[0]" value="No" /> No <br />
<input type="radio" id="choice-yes-2" name="choice[1]" value="Yes" /> Yes <br />
<input type="radio" id="choice-no-2" name="choice[1]" value="No" /> No <br />

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

In jQuery, how do I get the value of a radio button when they all have the same name?

How to get the NAME and value of a radio button when DYNAMICALLY selected - in jQuery?

How to get radio button value from multiple radio button with same v-model name?

php - Get radio button name attributes value

how get radio button value in javascript

How to Get a Count of Radio Button Value in PHP?

How get value of selected radio button in datalist

How to get the selected radio button’s value?

How to get value of selected radio button?

How to get the value of the selected radio button?

How to get value of selected radio button in angularjs

How to get value from radio button bootstrap

How to get the checked value of radio button in database?

How to get radio button value as a number

how to get the value of a radio button in blazor?

how to get checked radio button value in javascript

How to get the value of a radio button in a table - PHP

How to get the value of radio button in ColdFusion?

Get radio button value

How to get value from clicked radio button by refer its class name using jquery?

How to get boolean value of ,minimum 1 selected radio button from group ,by name(jquery)

Get value of radio button using li class name

How to get all radio button value into Json and load using local storage?

Get all the value of a radio button that is checked in a specific div

Get value of all radio button within a group. Jquery

how to set radio button same value if same name attr

How to check radio button with radio button value

How to get value of selected radio button returning the value

How to Get Value of Radio Button on Click and Subtract Value When Unchecked?