What's new

Closed How to count radio buttons?

Status
Not open for further replies.

Netflix

Forum Veteran
Joined
Jul 12, 2016
Posts
1,825
Reaction
816
Points
883
Can anybody help me how to count all the radio buttons that is selected?
Assume I have 15 buttons
Code:
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<input type="radio" name="kagawads">
<input type="radio" name="kagawads">
<input type="radio" name="kagawads">
<input type="radio" name="kagawads">
<input type="radio" name="kagawads">
<input type="radio" name="kagawads">
<input type="radio" name="kagawads">
<input type="radio" name="kagawads">
<input type="radio" name="kagawads">
<input type="radio" name="kagawads">
<input type="radio" name="kagawads">
<input type="radio" name="kagawads">
<input type="radio" name="kagawads">
<input type="radio" name="kagawads">


</body>
</html>


what do you prefer radio button or check box?
I would like to use this as a validation , user can only select less 7 or equal to 7.
TIA!
 
please change the variable name in order to track the count of the buttons
 
<form action="" method ="">
<input type="radio" name="kagawads1">
<input type="radio" name="kagawads2">
<input type="radio" name="kagawads3">
<input type="radio" name="kagawads4">
<input type="radio" name="kagawads5">
<input type="radio" name="kagawads6">
<input type="radio" name="kagawads7">
<input type="radio" name="kagawads8">
<input type="radio" name="kagawads9">
<input type="radio" name="kagawads10">
<input type="radio" name="kagawads11">
<input type="radio" name="kagawads12">
<input type="radio" name="kagawads13">
<input type="radio" name="kagawads14">
</form>

other file
count.php
conditional statement if(get(variables...))
then sum all variables
then you have the sum of all click buttons
 
how to count dynamic radio buttons selected using javascript

paste on google search hope this will help
 
Eto yung solution ko sa prob mo. Mas ok na checkbox para makapag select ka ng multiple. Tapos gawa ka nalang ng onclick event para ma-update mo yung current count ng selected checkboxes tapos dun mo narin i-validate.


<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<input type="checkbox" name="kagawads" checked>
<input type="checkbox" name="kagawads">
<input type="checkbox" name="kagawads" checked>
<input type="checkbox" name="kagawads" checked>
</body>
<script>
var count = document.querySelectorAll('input[type=checkbox]:checked').length;
console.log(count);
</script>
</html>
 
Thank you everyone.
I managed to do the work , through Php and ajax for setting and getting the multiple values in an array.

Thanks!
 
dapat po check box gamit mo.
if one answers for mutiple selection = radio button
if multiple answers for multiple selection = check box
 
Status
Not open for further replies.

Similar threads

Back
Top