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.
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.
Comments