homepage Welcome to WebmasterWorld Guest from 54.166.116.36
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Check to see if variable equals approved values
ocon

5+ Year Member



 
Msg#: 4461873 posted 2:06 am on Jun 6, 2012 (gmt 0)

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";

 

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4461873 posted 3:37 am on Jun 6, 2012 (gmt 0)

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;
}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved