Web Teacher Software
web database
Javacript 
Tutorial
CGI tutorial
web 
database consulting
web database training
contact us about web 
database software
press
Hosted Database Solutions
webteacher home
Web Teacher Consulting

javascript tutorial graphic


Webteacher Software now offers

if(Ret=="castle") {
location = 'ch03_1.html';
}
else {
alert("Please try again")
}


The if-then statement

The second line of the function is an if-then statement. It tells the computer that if the variable Ret equals "castle" then change the URL location to ch03_1.html. Otherwise, show the alert box which says "Please try again."

Here is the format of an if-then statement:
IF (a comparison)
{ sequence if the comparison is true }

ELSE { sequence is the comparison is false }

For example, let's say you've just had the reader complete a form which included their age. You want all Senior Citizens to get one message, and everyone else to get another when they submit the form.

age=form.age.valuetransfer the contents of the age box on the form to a variable called age.
if (age>=65)The if statement begins with the question in parentheses.
{alert("Your form has been submitted. Ask about our Senior Discounts") }
The alert box will be displayed if the question is true, age IS greater or equal to 65
ELSE {alert("Your form has been submitted.") }
The alert box command following the word ELSE will only be displayed if the question is false, and age IS NOT greater or equal to 65.

What's Next?
The entire tutorial in one zip file

Home | WebData - Web Database Software | Javascript | CGI | Consulting | Map Builder | Contact Us | The Press Room