JavaScript

Tuesday April 8, 2025
updated: April 10, 2002

 
Home
Getting Started
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Resources
Credits

 

 



Lesson 8 Example 2: If... Else Statement


Enter a value from 1 to 5:

 

HEAD BODY
<script>
function validate()
{
x=document.myForm
txt=x.myInput.value
if (txt>=1 && txt<=5)
{
alert("Thank you!")
return true
}
else
{
alert("Must be between 1 and 5")
return false
}
}
</script>

<form name="myForm" onsubmit="return validate()">

Enter a value from 1 to 5:
<input type="text" name="myInput">

<input type="submit" value="Send input">

</form>

back button
next button

© 2002 Tracy Johnson