Link to home
Start Free TrialLog in
Avatar of FastEddie___
FastEddie___

asked on

Checking a Drop Down Value against a Javascript Numeric Array List

I would like to check an drop down list value on a form page with a numeric list to see if the value is in the list.
How can this be done via Javascript?

For example:
 
var myList = new Array(2,3,14,25); // the id list to check against

var fieldVal = thing[thing.selectedIndex].value; // the numeric selected drop down field value


if(fieldVal == myList[idx])
    alert("Yes the drop down value is in my array list");
else
    alert("No. the drop down value is not in the array list");

ASKER CERTIFIED SOLUTION
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of agileblowfish
agileblowfish


for (var i=0; i < myList.length; i++) {
	if (fieldVal == myList[i]) {
		alert("Yes the drop down value is in my array list");
	}else{
		alert("No. the drop down value is not in the array list");
	}
}

Open in new window

Avatar of FastEddie___

ASKER

Thanks