Multiple 'If statements' - is their an easier way to write the following....

  • 13 years ago

    I would like the below 'if' statements to be written in a more clear and easier way, what are my options: (Many Thanks)

            var locationID=document.getElementById("locationID");

            if (locationID.value!="England")
            if (locationID.value!="Wales")
            if (locationID.value!="Ireland")
            if (locationID.value!="Scotland") {
                alert("Please enter a location");
                return false;
            }





  • 13 years ago
    Hi Nitesh

     Instead of using above if statement...u can utilize the switch....case statement...as per the follwoing method.





    var locationID=document.getElementById("locationID").value;
    var blnStatus;
    switch(locationID)
    {
        case "England":
        case "Wales":
        case "Ireland":
        case "Scotland":
                 blnStatus=true;
        default:
            alert("Please enter location");
            blnStatus=false;
            break;
    }
     
    return blnStatus;

















    Good Luck

    Regards
    Hari K......





Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The greatest performance improvement of all is when a system goes from not-working to working.” - John Ousterhout