HoloGuides :: Know Everything ! Knowledge
Programming
JavaScript . if (then) else



  conditional execution
  if() {...} [else {...}]
  Netscape Reference
Overture Search the Web.
  Description

Conditional execution is used whenever the flow of the program depends on some variables.
Usage
. check if the user input is valid
. has the calculation reached a critical point

  Syntax

if(condition)
 {
 statements
// this is executed if condition evaluates to true
 }
// optional
else
 {
 other statements
// this is executed if condition evaluates to false
 }

  Syntax example

if (myVariable == 10) // use the proper comparision operator (see below)
{
statements if condition is true;
// this is executed if myVariable is 10
}
// optional
else
{
statements if condition is false;
// this is executed if variable is not 10
}

comparison operators
== is equal
!= is different
< is less than
<= is less than or equal
>= is equal or greater than
> is greater than

 

  Working sample

 

Accept a form only if the user has filled-in the required email field

if (emailVariable == '') // important : use the == operator to compare, not the = to assign
{
alert("no email given");
}

[Composant FrontPage Enregistreur de résultats]

email

for a complete check email example click here

 



Banner Barter