dev.kanngard.net make sure you visit my new blog at: johankanngard.net

Short tip: Check if a SELECT contains a specific value

by Johan Känngård / [JavaScript] / 2003-01-14 / #42


This simple function checks if the specified select contains the specified value and alias.

/**
 * Returns true if 'sV' (value) and 'sA' (alias) is contained in the options list 'l'
(in the same option object)
 *
 * @author Johan Känngård, http://dev.kanngard.net
 */
function selectContains(l, sV, sA) {
	for(j=0;j<l.length;j++) {
		if((l[j].value==sA) &&(l[j].text==sV)){
			return true;
		}
	}
	return false;
}