The short answer is no.
You need to compare each individual option with the || .
Another option is to use regexp as follows:
function validate() { var values = ['this', 'that', 'those']; if (document.getElementById('check_value').value.search(new RegExp('^('+values.join('|')+')$')) > -1) { $('#block').fadeIn('slow'); } else { alert("Nope. Try again"); } }
Fiddle: http://jsfiddle.net/78PQ8/1/
You can also create your own prototype of this type of action:
String.prototype.is = function(){ var arg = Array.prototype.slice.call(arguments); return this.search(new RegExp('^('+arg.join('|')+')$')) > -1; }
and the call is as follows:
function validate() { if (document.getElementById('check_value').value.is('this', 'that', 'those')) { $('#block').fadeIn('slow'); } else { alert("Nope. Try again"); } }
source share