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 1: If Statement


Enter your E-mail address:

This example only tests if the email address contains an "@" character. Any "real life" code will have to test for punctuation, spaces and other things as well.

Code Head Code for Body
<script>
function validate()
{
x=document.myForm
at=x.myEmail.value.indexOf("@")
if (at == -1)
{
alert("Not a valid e-mail")
return false
}
}
</script>

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

Enter your E-mail address:
<input type="text" name="myEmail">
<input type="submit" value="Send input">
</form>


back button
next button

© 2002 Tracy Johnson