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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error checking multiple select boxes

Status
Not open for further replies.

trojan800

Programmer
Nov 27, 2001
53
US
I have a dynamically created page that creates a bunch of select boxes (dropdowns) all named the same thing. When the user submits the page I need to validate the page and make sure that none of the select boxes still have the default value (99999). The problem is I am not sure how to cycle through the dropdowns. Here is my code below. Please note that the code for the 'title' textboxes (that have been created the same way) works just fine.

for (i = 0; i < arraycount; i++)
{
if (form.title.value == "")
{
alert ("You can't leave any titles empty.");
return false;
}
}

for (i = 0; i < arraycount; i++)
{
if (form.category.options[form.category.selectedIndex].value == "99999")
{
alert ("You must choose a category for each award.");
return false;
}
}

Thanks for any and all help in advance.
-Rory
 
You could use:
Code:
function checkEm(){
	var allselects = document.getElementsByTagName("select");
	var err = false;
	for (var i = 0; i < allselects.length; i++) {
		if (allselects[i].value != "99999") {
			err = true;
		}
	}
	if(err == true){
		alert("Please correct error");
		return false;
	} else {
		return true;
	}
}

-----

_brian.
 
sorry, one mistake there:
this:
Code:
if (allselects[i].value != "99999") {

should be this:
Code:
if (allselects[i].value == "99999") {

-----

_brian.
 
This would probably work better:
Code:
if (allselects[i][allselects[i].selectedIndex].value == "99999")

Lee
 
Thanks Brian! That works perfectly! A star for you...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top