Page 1 of 1
counting
Posted: Tue Sep 13, 2011 8:49 am
by naveendk.55
Hi, I'm new to javascripting. I need help with below code.
There are six html <select> tags. Each tag has options YES, NO and NA. I want to count the number of 'NO' selected by the user and assign it to a textbox value. help please.
Re: counting
Posted: Wed Sep 14, 2011 11:53 am
by KCAstroTech
If you are using jQuery (
http://www.jquery.com) then you could use:
It is a bit vague but that should work. Essentially you are telling jQuery to look at ALL select tags and find only the ones with the value of "NO" presuming of course that the select looks something like:
Code: Select all
<select>
<option value="YES">YES</option>
<option value="NO">NO</option>
<option value="NA">NA</option>
</select
Otherwise you have to use some sort of loop like:
Code: Select all
//Create a variable called selects then assign it an array of the all of select elements in the document
var selects = document.getElementsByTagName('select');
//Loop through the selects
for(var i in selects){
//Check if the select's value equals "NO"
if(selects[i].value == 'NO'){
//If the select's value is no then do something here
}
}