You are on page 1of 2

ASSIGNMENT NO: 02 (SPRING 2012)

INTRODUCTION TO COMPUTING (CS 101)


TOTAL MARKS: 20

Objective: To develop your own JavaScript functions and using them in form.

QUESTION NO: 01

Marks: 20

Make a form in HTML document containing only one field named as Email and one Submit
Button. Write your own JavaScript function to validate the email address.

<Html>
<Title>cs101 assignment no: 02 spring 2012</Title>
<Head>
<Script>
Function validateForm ()
{
Var x=document.forms ["myform"]["email"].
Value; var atpos=x.indexOf ("BC120200536@vu.edu.pk");
Var dotpos=x.lastIndexOf (".");
If (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
{
Alert ("Enter valid E-mail address");
Return false;

}
}
</script>
</head>
<Body bgcolor="#9966cc">
<Body>
<form name="myForm" action="demo_form.asp" onsubmit="return
ValidateForm ();" method="post">
Email: <input type="text" name="email">
<input type="submit" value="Submit">
</form>
</body>
</html>
Email:
Submit

You might also like