BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
JavaScript
JavaScript Boolean Object
JavaScript Assertiveness
JavaScript Array Object Functions
JavaScript Arrays
JavaScript Variables
How to use JavaScript?
JavaScript Guidelines
Stock sorter example for IE5
Confused about how to use a data island in IE5??
Software Release tracking application
Employee Phonebook dataisland
Multitab DHTML browser
Trim function in Javascript
Multiple Grid
Re: Trim Function in JavaScript
Re: Trim Function in JavaScript
Trim Function in JavaScript using Regular Expressions.
DHTML ScoreBoard Behavior
Re: JScript Super Class To Handle XML Transformations
Updated: Detect XML Parser version using Javascript
 
LAMP >>

By :Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :03/24/2008
Times viewed :639

 

JavaScript Conditional Statements

Introduction

Conditional statements can be used to perform certain tasks depended on the condition. In the real like, you are using these statements nearly each day and many times. For example, if you are standing in front of a red light on the street, then you can say that you will cross the link “if” it shows green. In the programming world, you could use this example: If the variable is empty then show an error message. There are two different condition statements: if…else and switch. Both perform in saw way the same task. The following example demonstrates it.

Example of if statement

This example checks if the variable x is empty. If it is empty then it will show an error message.

<html>

<head>

<script type="text/javascript">

            var x = ""

            if( x == ""){

                        document.write("Error: Variable is empty<br/>")

                        document.write("Please fill the variable.")

            }

            else

                        document.write(x)

</script>

</head>

<body></body>

</html>

Output

Switch statement

Switch statements works the same as if statements. However the difference is that they can check for multiple values. Of course you do the same with multiple if..else statements, but that really doesn’t look good. The following shows how it will look like:

if(light == "red ")

            document.write("You can not drive now")

if(light == "yellow")

            document.write("You can drive if you want")

if(light == "green")

            document.write("Now you can drive.")

Example of Switch Statement

<html>

<head>

<script type="text/javascript">

            var light = "green"

            switch(light)

            {

                        case "red":

                                    document.write("You can not drive now.")

                                    break

                        case "yellow":

                                    document.write("You can drive if you want.")

                                    break

                        case "green":

                                    document.write("You can drive now.")

                                    break

                        default:

                                    document.write("Light is not working...")

            }

</script>

</head>

<body></body>

</html>

Output


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

An immediate job opportunity as a B
Software Developers Needed in Charl
Sr. Software Engineer - Analytics
Immediate Mainframe openings for Ch
Immediate TANDEM-TAL openings for C

View all Jobs (Add yours)
View all CV (Add yours)



answering service
go to meeting
swimming pool contractor
teleconferencing
water softener
Teleconference
Host Department NOLIMIT Web Hosting
MSN
sunglasses


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP