0% found this document useful (0 votes)
90 views

Vnrvjiet: : Sheet No Name of Laboratory: Name of Experiment: Web Technologies Experiment No: 12

The document contains code for a student registration form validation using JavaScript regular expressions. The form contains fields like name, password, gender, languages known etc. and validates the name field to start with capital letter followed by full name, password to have minimum 6 characters and both password fields to match. On submit, it calls a validate() function that checks the field values against the regular expressions and displays appropriate error messages.

Uploaded by

Venky Telaprolu
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

Vnrvjiet: : Sheet No Name of Laboratory: Name of Experiment: Web Technologies Experiment No: 12

The document contains code for a student registration form validation using JavaScript regular expressions. The form contains fields like name, password, gender, languages known etc. and validates the name field to start with capital letter followed by full name, password to have minimum 6 characters and both password fields to match. On submit, it calls a validate() function that checks the field values against the regular expressions and displays appropriate error messages.

Uploaded by

Venky Telaprolu
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 25

VNRVJIET

Name of Laboratory: Web Technologies

Sheet No: 25 Name of Experiment: Experiment No: 12


Arithmetic operations

Date: 20/8/2011

AIM: Javascript program for performing basic arithmetic operations PROGRAM: <html> <head><title>Arithmetic operations</title></head> <body> <script type="text/javascript"> var op1,op2,r,op; op=window.prompt("1.Addition 2.Subtraction 3.Multiplication 4.Division \nEnter your choice","1"); op=parseInt(op); if(op>=1&&op<=4) { op1=window.prompt("Enter the first operand","0"); op1=parseInt(op1); op2=window.prompt("Enter the second operand","0"); op2=parseInt(op2); switch(op) { case 1: r=op1+op2; break; case 2: r=op1-op2; break; case 3: r=op1*op2; break; case 4: r=op1/op2; break; } window.alert("Result "+r); } else document.writeln("You have entered the wrong choice"); </script> </body> </html>

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 26 Name of Experiment: Experiment No: 12


Arithmetic operations

Date: 20/8/2011

OUTPUT:

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 27 Name of Experiment: Experiment No: 12


Arithmetic operations

Date: 20/8/2011

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 28 Name of Experiment: Experiment No: 13


Finding factorial

Date: 20/8/2011

AIM: Javascript program for finding the factorial PROGRAM: <html> <head><title>Factorial</title></head> <body> <script type="text/javascript"> var num,i,fact=1; num=window.prompt("Enter a number : ","0"); num=parseInt(num); for(i=num;i>=1;i--) fact=fact*i; window.alert("Factorial "+fact); </script> </body> </html>

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 29 Name of Experiment: Experiment No: 13


Finding factorial

Date: 20/8/2011

OUTPUT:

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 30 Name of Experiment: Experiment No: 14


Fibonacci series

Date: 20/8/2011

AIM: Javascript program for finding Fibonacci series PROGRAM: <html> <head><title>Fibonacci</title></head> <body> <script type="text/javascript"> var a=0,b=1,num,i,c; num=window.prompt("Enter a number : ","0"); num=parseInt(num); document.writeln("<p>"+"Fibonacci series upto "+num+" terms"+"</p>"); document.writeln("0 1 "); for(i=0;i<num-2;i++) { c=a+b; a=b; b=c; document.writeln(c); } </script> </body> </html>

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 31 Name of Experiment: Experiment No: 14


Fibonacci series

Date: 20/8/2011

OUTPUT:

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 32 Name of Experiment: Experiment No: 15


Exception handling

Date: 27/8/2011

AIM: Javascript program to illustrate try,catch,throw statements PROGRAM: <html> <head><title>Exception Handling</title></head> <body> <script type="text/javascript"> var txt; try { adddlert("Welcome guest"); } catch(err) { txt="There was an error on this page\n"; txt=txt+"Error description : "+err.description+"\n"; txt=txt+"Click OK to continue"; alert(txt); } </script> </body> </html>

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 33 Name of Experiment: Experiment No: 15


Exception handling

Date: 27/8/2011

OUTPUT:

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 34 Name of Experiment: Experiment No: 16


Javascript events

Date: 27/8/2011

AIM: Javascript program for illustrating different javascript events PROGRAM: <html> <head><title>JavaScript Events</title></head> <body onLoad="load()" onUnLoad="unLoad()"> <a href="http://www.google.com">Search</a><br><br><br> <img src="logo1.jpg" onMouseOver="mouseOver()"></img><br><br><br><br><br><br> <form action=""> <input type="text" onFocus="focus()" onChange="change()"/> <input type="submit"/> </form> <script type="text/javascript"> function load() { window.alert("Welcome!"); } function unLoad() { window.alert("Bye!"); } function mouseOver() { window.alert("Self-Explanatory"); } function focus() { window.alert("Type your name"); } function change() { window.alert("Change"); } </script> </body> </html>

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 35 Name of Experiment: Experiment No: 16


Javascript events

Date: 27/8/2011

OUTPUT:

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 36 Name of Experiment: Experiment No: 16


Javascript events

Date: 27/8/2011

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 37 Name of Experiment: Experiment No: 17


Javascript objects

Date: 27/8/2011

AIM: Javascript program for illustrating javascript objects PROGRAM: <html> <head><title>JavaScript String object</title></head> <body> <script type="text/javascript"> var str="I am an Indian"; document.write("<b>"+"String object"+"</b>"); document.write("<br>"); document.write("String : "+str); document.write("<br>"); document.write("String Length: "+str.length); document.write("<br>"); document.write("Index of Indian: "+str.indexOf("Indian")); document.write("<br>"); document.write("Replace I am with She is: "+str.replace("I am","She is")); document.write("<br>"); document.write("Check match: "+str.match("I am")); document.write("<br>"); document.write("Uppercase: "+str.toUpperCase()); document.write("<br>"); document.write("<br>"); var d=new Date(); var h,m,s; document.write("<b>"+"Date object"+"</b>"); document.write("<br>"); document.write("Today's date : "+d); document.write("<br>"); document.write("Milliseconds since 1/1/1970 : "+d.getTime()); document.write("<br>"); document.write("To string : "+d.toUTCString()); document.write("<br>"); document.write("Day of week : "+d.getDay()); document.write("<br>");

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 38 Name of Experiment: Experiment No: 17


Javascript objects

Date: 27/8/2011

h=d.getHours(); m=d.getMinutes(); s=d.getSeconds(); document.write("Time : "+h+":"+m+":"+s); document.write("<br>"); document.write("<br>"); document.write("<b>"+"Math object"+"</b>"); document.write("<br>"); document.write("Round: "+Math.round(0.45)); document.write("<br>"); document.write("Random number b/w 0 and 1: "+Math.random()); document.write("<br>"); document.write("Max: "+Math.max(1,2,3,4,0)); document.write("<br>"); document.write("Min: "+Math.min(9,18)); document.write("<br>"); document.write("<br>"); var r=new RegExp("we"); document.write("<b>"+"RegExp object"+"</b>"); document.write("<br>"); document.write("Test: "+r.test("Individually, we are one drop Together, we are an ocean.")); document.write("<br>"); document.write("Exec: "+r.exec("Individually, we are one drop Together, we are an ocean.")); document.write("<br>"); r.compile("abc"); document.write("RexExp is changed to abc"); document.write("<br>"); document.write("Test: "+r.test("Individually, we are one drop Together, we are an ocean.")); document.write("<br>"); document.write("Exec: "+r.exec("Individually, we are one drop Together, we are an ocean.")); document.write("<br>"); document.write("<br>");

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 39 Name of Experiment: Experiment No: 17


Javascript objects

Date: 27/8/2011

var fruits=["mango","banana","guava","strawberry"]; var veg=["carrot","brinjal","potato"]; var con=fruits.concat(veg); document.write("<b>"+"Arr object"+"</b>"); document.write("<br>"); document.write("Concat: "+con); document.write("<br>"); document.write("Join: "+con.join(" and ")); document.write("<br>"); document.write("Sort: "+con.sort()); document.write("<br>"); document.write("<br>"); </script> </body> </html>

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 40 Name of Experiment: Experiment No: 17


Javascript objects

Date: 27/8/2011

OUTPUT:

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 41 Name of Experiment: Experiment No: 18


Reg form validation

Date: 27/8/2011

AIM: Javascript program to validate student registration form PROGRAM:


<html> <head> <title>Student Registration Form</title> <script type="text/javascript"> var name=new RegExp("^[A-Z] [A-Z][a-z]+$"); var pwd=new RegExp("[A-Za-z0-9!@#$%^&*()]{6,}"); function validate() { var valid; var fld1=document.myform.name.value; var fld2=document.myform.pwd.value; var fld3=document.myform.confpwd.value; if(fld1.length==0) { alert("Enter your name.This field cannot be left empty"); valid=false; } else if(fld1.match(name)) valid=true; else { alert("Please enter a valid name.It should start with your initial in capital followed by your name"); valid=false; } if((fld2.match(pwd))&&(fld2.match(fld3))) valid=true; else if(!fld2.match(pwd)) { alert("Re-enter your password.It should consist of atleast 6 characters"); valid=flase; } else { alert("Re-enter your password.Both password entries did not match"); valid=false; } }

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 42 Name of Experiment: Experiment No: 18


Reg form validation

Date: 27/8/2011

</script> </head> <body> <h2 align="center">Student Registration Form</h2> <form name="myform" onsubmit="return validate();" method="post" action="js8.html"> <fieldset> <legend align="center">Personal Information</legend> <b>Name :</b> <input type="text" title="Name" name="name"/><br> <b>Password :</b> <input type="password" title="Password" name="pwd"/><br> </fieldset> <b>Confirm Password :</b> <input type="password" title="Confirm Password" name="confpwd"/><br><br> <b>Self Description :</b> <br><textarea rows="5" cols="25"></textarea><br> <b>Languages known :</b> <br> <input type="checkbox">English</input><br> <input type="checkbox">Telugu</input><br> <input type="checkbox">Hindi</input><br> <b>Gender :</b> <br> <input type="radio">Male</input><br> <input type="radio">Female</input><br> <b>Programming Languages :</b> <br> <select> <option selected>C</option> <option>C++</option> <option>Java</option> <option>C#.NET</option> </select><br><br> <select multiple> <option selected>C</option> <option>C++</option> <option>Java</option> <option>C#.NET</option> <option>ASP.NET</option> </select><br> <input type="submit" value="Submit"/> </form> </body> </html>

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 43 Name of Experiment: Experiment No: 18


Reg form validation

Date: 27/8/2011

OUTPUT:

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 44 Name of Experiment: Experiment No: 18


Reg form validation

Date: 27/8/2011

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 45 Name of Experiment: Experiment No: 19


Email validation

Date: 27/8/2011

AIM: Javascript program to validate email id PROGRAM:


<html> <head> <title>Student Registration Form</title> <script type="text/javascript"> var email=new RegExp("^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$"); function validate() { var valid; var fld1=document.myform.eid.value; if(fld1.length==0) { alert("Enter email id.This field cannot be left empty"); valid=false; } else if(fld1.match(email)) valid=true; else { alert("Please enter a valid email id"); valid=false; } } </script> </head> <body> <form name="myform" onsubmit="return validate();" method="post" action="js7.html"> <b>Name :</b> <input type="text" title="Name" name="name"/><br> <b>Email id :</b> <input type="text" title="Email id" name="eid"/><br> <input type="submit" value="Submit"/> </form> </body> </html>

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 46 Name of Experiment: Experiment No: 19


Email validation

Date: 27/8/2011

OUTPUT:

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 47 Name of Experiment: Functions in javascript Experiment No: 20 Date: 27/8/2011

AIM: Javascript program to illustrate functions PROGRAM: <html> <head> <script type="text/javascript"> function dispmsg() { alert("Hello World!"); } </script> </head> <body> <form> <input type="button" value="Press me!" onclick="dispmsg()" /> </form> </body> </html>

VNRVJIET
Name of Laboratory: Web Technologies

Sheet No: 48 Name of Experiment: Functions in javascript Experiment No: 20 Date: 27/8/2011

OUTPUT:

You might also like