Welcome to WebmasterWorld Guest from 23.22.46.195

Forum Moderators: open

Check to see if variable equals approved values

   
2:06 am on Jun 6, 2012 (gmt 0)

5+ Year Member Top Contributors Of The Month



I'm trying to set a variable equal to the value of an url parameter. If this value does not match one of the approved values then I need to set this variable to a default value.

I'm using or statements right now, but this gets kind of ridiculous when you have many different approved values. Is there some kind of shorthand or better way of doing this?


var lang = [grab value of lang parameter if set];

if(lang!="en" || lang!="es" || lang!="pt" || lang!="ja" || lang!="zh" || ...) lang = "ko";
3:37 am on Jun 6, 2012 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



You could use a switch statement:

var lang = [grab value of lang parameter if set];
switch (lang) {
case 'en':
case 'es':
case 'pt':
case 'ja':
case 'zh':
lang = 'ko';
break;
default:
lang = 'XX';
break;
}
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month