If statement

If- In this type of statement if the condition is true then the written statement will get executed otherwise nothing will happen.

E.g.1
<html> 

<head> 

<title>If Statement</title> 

<script language="javascript">

var age=prompt("Enter Your Age");

if(age > 17)

{

alert("Qualified for voting")

}

</script>

</head> 

<body>

Are you qualified for voting? 

</body> 

</html>  
E.g.2
<html> 

<head> 

<title>If Statement</title> 

</head> 

<body>

Are you qualified for voting? 

<form>

Enter you age:<input type="text" name="usrage">

<input type="button" onclick="check(this.form)" value="Check">

</form>

<script language="javascript">

function check(form)

{

if(form.usrage.value > 17)

{

alert("Qualified for voting")

}

}

</script>

</body> 

</html>  
Check Output:
Enter age value greater than 17 to get result otherwise you will not get any response
If Statement Are you qualified for voting?
Enter you age:

Related Topics:
  1. JavaScript Introduction
  2. Variables in JavaScript
  3. JavaScript Function
  4. Accessing JavaScript Function
  5. Creating JavaScript interactive form
  6. Accessing form field value
  7. Creating interactive form login webpage
  8. Networking Fundamentals
  9. TCP/IP and Internet addressing
  10. Internet Working
  11. Internet Working Servers
  12. Concept and need for web publishing
  13. Web languages
  14. Javascript Control Structure
  15. Checking Text is Letter/s
  16. Checking Text is Number/s
  17. Checking Textbox is Empty or not
  18. Addition of two numbers
  19. Subtraction of two numbers
  20. Multiplication of two numbers
  21. Division of two numbers
  22. Form field validations
  23. Email validation