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.
counting
Moderator: General Moderators
-
KCAstroTech
- Forum Commoner
- Posts: 33
- Joined: Sat Aug 27, 2011 11:16 pm
Re: counting
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:
Otherwise you have to use some sort of loop like:
Code: Select all
$("select[value='NO']")Code: Select all
<select>
<option value="YES">YES</option>
<option value="NO">NO</option>
<option value="NA">NA</option>
</select
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
}
}