Beework Web Design Logo

  Search

  

Skype: beeworkweb
Email:info@beework.net

Sales (free):
0800 882 4173

Support:
0870 978 0583

Mobile:
07866 627185

Registered Member of the UK Web Design Association 
Registered Member
of the UK Web Design
Association

Valid XHTML 1.0 Strict



Generate the JavaScript Code for an If Then Else Statement

Generates JavaScript if then code. Just Click the button to see the If Then Syntax. 

Copy and paste this code to the <HEAD> section of your page

Conditional statement

Use the if statement to perform certain statements if a logical condition is true; use the optional else clause to perform other statements if the condition is false. An if statement looks as follows:

if (condition) {
          statements1
[ } else {
          statements2 ]
}
The condition can be any JavaScript expression that evaluates to true or false. The statements to be executed can be any JavaScript statements, including further nested if statements. If you want to use more than one statement after an if or else statement, you must enclose the statements in curly braces, {}.

Example. In the following example, the function checkData returns true if the number of characters in a Text object is three; otherwise, it displays an alert and returns false.

function checkData () {
          if (document.form1.threeChar.value.length == 3) {
                    return true
} else {
alert("Enter exactly three characters. " +                     
          document.form1.threeChar.value + " is not valid.")
return false
}
}