Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

count certain array items 1

Status
Not open for further replies.

project3

Technical User
Jan 10, 2008
22
US
What I have is a form with select box named in array
name=s_active[]

what I want to do is prevent the form from being submitted if the array has more than 3 values=yes

I know how to work with arrays but am unsure how to count only ones with a certain value.

Thanks in advance!!
 
Do you mean that you want to check to see how many options in a select are selected?

Lee
 
no I want if yes is selected more than 3 times return false.
 
I have got it almost figured out i can do it with an array i put in the code but Im having trouble pulling an array out of the input boxes in the html

I tried
var arr = document.theform.s_active[].value;

but that doesn't work how do i pull the array values in?
 
You can't use square brackets like that in Javascript. Try accessing it through an associative array like this:
Code:
document.forms['theform'].elements['s_active[]'].value;

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top