Issue
This is HTML:
<select class="form-control selectVitrat" name="PVSuperior" id="PVSuperior">
<option value="NO">NU</option>
<option value="YES">DA</option>
</select>
<select class="form-control selectVitrat" name="PVIntermediar9" id="PVIntermediar9">
<option value="NO">NU</option>
<option value="YES">DA</option>
</select>
<select class="form-control selectVitrat" name="PVIntermediar8" id="PVIntermediar8">
<option value="NO">NU</option>
<option value="YES">DA</option>
</select>
How can I count how many Yes I selected from these multiple selections?
Solution
In JavaScript, you can use getElementsByTagName
to get all the select
. And using for
loop, you can check how many select
have YES values:
function checkTotalYes() {
var selectElements = document.getElementsByTagName("select");
var count = 0;
for (var i = 0; i < selectElements.length; i++) {
if (selectElements[i].value == 'YES')
count++;
}
console.log('Total Yes: ' + count);
}
checkTotalYes();
<select class="form-control selectVitrat" name="PVSuperior" id="PVSuperior" onchange="checkTotalYes()">
<option value="NO">NU</option>
<option value="YES">DA</option>
</select>
<select class="form-control selectVitrat" name="PVIntermediar9" id="PVIntermediar9" onchange="checkTotalYes()">
<option value="NO">NU</option>
<option value="YES">DA</option>
</select>
<select class="form-control selectVitrat" name="PVIntermediar8" id="PVIntermediar8" onchange="checkTotalYes()">
<option value="NO">NU</option>
<option value="YES">DA</option>
</select>
Answered By - Milan Chheda
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.