If else if

If...else if- In this type of statement it executes the statement code following a condition that evaluates to true. If no condition evaluates to true then statement code following else gets executed

E.g.

<html> 
<head> 
<title>If...else if statement</title> 
</head> 
<body>
What's your grade?  
<form>
Enter marks:<input name="stumarks" type="text" />
<input onclick="check(this.form)" type="button" value="Check" />
</form>
<script language="JavaScript">
function check(form)
{
if(form.stumarks.value>100)
{
alert("Not valid marks! Enter again")
} 
else if(form.stumarks.value>89)
{
alert("Got grade A+")
}
else if(form.stumarks.value>79)
{
alert("Got grade A")
}
else if(form.stumarks.value>69)
{
alert("Got grade B+")
}
else if(form.stumarks.value>59)
{
alert("Got grade B")
}
else if(form.stumarks.value>39)
{
alert("Got grade C")
}
else if(form.stumarks.value>29)
{
alert("Got grade D")
}
else if(form.stumarks.value>0)
{
alert("Re-appear again")
}
else
{
alert("Unknown value")
}
}
</script>
</body> 
</html>
Check Output:
If...else if statement What's your grade?
Enter marks:
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