multiple strings to a single var in javascript/Jquery

I've created an input and a button. When you press the button, if you put one of 3 states in it makes certain panels appear and disappear. This part works fine. The only problem is that it only accepts the input if you do a lowercase nj.

How can I change my code to accept both lowercase, upper case, and the word New Jersey spelled out in full?

var stateSearch, searchButton, nj, pa
nj = "nj";
stateSearch = $("#stateSearch").val();

if (stateSearch === nj) {


Make a dictionary to accept these different versions

var acceptState = {
    "NJ" : true,
    "NEW JERSEY" : true

And then use toUpperCase when you check this dictionary

if (acceptState[stateSearch.toUpperCase()]) {

You can force the user input to lower case to match the string you're testing against by using toLowerCase(). Try this:

if (stateSearch.toLowerCase() === nj) {
    // your code...

Need Your Help

Get source from pre-compiled ASP.NET website?

c# visual-sourcesafe decompiling

Long story short, VSS decided I wasn't allowed to have some code changes. I am missing a decent sized feature that I don't want to have to re-write (gave to a co-op as work this past summer). It wo...

Additional lint rules in Android

android jenkins android-lint

I want to include some additional lint rules in my Android project. And by additional rules, i mean that i just want to include some extra rules from the list given in Android Studio( Pic attached)...