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: