SlideShare a Scribd company logo
VADODARA INSTITUTE OF ENGINEERING
ACTIVE LEARNING ASSIGNMENT
Web Technology (2160708)
TOPIC : Form using HTML and Java scripts with validation
Presented By:
Kashyap Patel 150800107046
Krishna Patel 150800107047
Maitree Patel 150800107048
:
Content
 HTML Forms
• Introduction
• The <input> Element
• HTML Form Controls
• Form Attribute
Java script with validation
• Why do we need validation
• JavaScript form validation example
HTML Forms
Introduction :
• HTML Forms are required when some data needs to be collected.
• For example during registration information like name, email-id, address etc.
• A Form will take input form the site visitor and then post into a backend
application.
• It will perform require processing on the pass data based on defined business logic
inside application.
Introduction
• The HTML <form> element defines a form that is used to collect user input:
• <form>
.
form elements
.
</form>
• An HTML form contains form elements.
• Form elements are different types of input elements, like text fields, checkboxes,
radio buttons, submit buttons, and more.
The <input> Element
• The <input> element is the most important form element.
• The <input> element can be displayed in several ways, depending on
the type attribute.
• Here are some examples:
Type Description
<input type="text"> Defines a one-line text input field
<input type="radio"> Defines a radio button (for selecting one of
many choices)
<input type="submit"> Defines a submit button (for submitting the
form)
HTML Form Controls
1. Text Input
There are 3 types of text input control used on forms.
• Single line Text Input control
<form>
First name:<br>
<input type="text" name="firstname"><br>
</form>
file:///D:/wt/new%201.html
HTML Form Controls
• Password Input Control
This also single line Text input but it makes characters as soon as user enter
it.
Ex.Password < input type = “Password” name=“password”/>
HTML Form Controls
• Multiple line Input Control
This is used when user is required to give details that may be longer than single
sentence.
ex. <textarea rows = “3” cols = “5” >
HTML Form Controls
2. Checkbox Control
It is used when more than one option is required to be selected.
Ex.
<input type = "checkbox" name = "maths" checked>maths<br>
<input type = "checkbox" name = "wt" uchecked>wt<br>
HTML Form Controls
3. Radio Button
Radio buttons are used when out of many options just one option is required to be
selected.
• Ex<form>
<input type="radio" name="gender" value="male" checked> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other
</form>
HTML Form Controls
4. Select box Control (Drop down Box)
It provide <option> tag to list out various option in form of drop down list.
Ex. <select name=“Subject”>
<option value=“maths”>maths</option>
<option value=“physics”>physics</option>
<option value=“chemistry”>chemistry</option>
HTML Form Controls
5. File upload box
If you want to allow user to upload the file used file upload box.
Name and accept are attribute.
Ex.<input type=“file" name=“upload" accept= “jpg.doc”/>
HTML Form Controls
6. Button controls
• Submit Button : This creates a button that automatically submits a form.
Ex. <form>
First name:<br>
<input type="text" value="Mickey"><br>
Last name:<br>
<input type="text" name="lastname" value="Mouse"><br><br>
<input type="submit" value="Submit">
</form>
HTML Form Controls
• Reset Button: This creates a button that automatically reset form controls to their
initial value.
Ex.
First Name:<br>
<input type="text" name=“First Name”><br>
Last Name<br>
<input type="text" name=“Last Name" ><br><br>
<input type="submit" value="Submit">
<input type=“reset" value=“Reset">
HTML Form Controls
• Button : This creates a button that is used to trigger client side script when the
user click that button.
Ex. <input type=“button" value=“button">
• Image : This creates a clickable button but we can used ad image as background
of the button.
Ex. <input type = “image" src = "pexels-photo-547114.jpeg">
Form Attributes
1. The Action Attribute
• The action attribute defines the action to be performed when the form is
submitted.
• Normally, the form data is sent to a web page on the server when the user clicks
on the submit button.
Ex. <form action="/action_page.php">
2. The Name Attribute
• Each input field must have a name attribute to be submitted.
• If the name attribute is omitted, the data of that input field will not be sent at all.
Form Attributes
3. The Method attribute
• It specifies how to send form data.
• The form data is send to the page specified in the action attribute.
Ex. <form action="/action_page.php" method="get">
• when GET is used, the submitted form data will be visible in the page address
field:
/action_page.php?firstname=Mickey&lastname=Mouse
Ex. <form action="/action_page.php" method="post">
• POST if the form data contains sensitive or personal information. The POST
method does not display the submitted form data in the page address field.
Form Attributes
4. The Target Attribute
• The target attribute specifies if the submitted result will open in a new browser
tab, a frame, or in the current window.
• _blank : the response is display in new window or tab.
• _self : the response is displayed in same frame.
• _parent : the response is displayed in parent frame.
• _top : display full body of the window.
• _framename : display in name frame.
Java script with validation
• It is important to validate the form submitted by the user because it can have
inappropriate values. So validation is must.
• The JavaScript provides you the facility the validate the form on the client side so
processing will be fast than server-side validation. So, most of the web developers
prefer JavaScript form validation.
• Through JavaScript, we can validate name, password, email, date, mobile number
etc fields.
JavaScript form validation example
<html><body>
<script>
function validateform(){
var name=document.myform.name.value;
var password=document.myform.password.value;
if (name==null || name==""){
alert("Name can't be blank");
return false; }
else if(password.length<6){
alert("Password must be at least 6 characters long.");
return false; } } </script>
JavaScript form validation example
<body>
<form name="myform" method="post" action="abc.jsp" onsubmit="return validatef
orm()" >
Name: <input type="text" name="name"><br/>
Password: <input type="password" name="password"><br/>
<input type="submit" value="register">
</form>
JavaScript form validation example
<html>
<head> <title>Form Validation</title>
<script ty
pe="text/javascript"> </script>
function validate()
{ if( document.myForm.Name.value == "" )
{ alert( "Please provide your name!" );
document.myForm.Name.focus() ;
return false; }
JavaScript form validation example
if( document.myForm.EMail.value == "" )
{ alert( "Please provide your Email!" );
Document.myForm.EMail.focus() ;
return false; }
if( document.myForm.Zip.value == "" ||
isNaN(document.myForm.Zip.value ) ||
document.myForm.Zip.value.length != 5 )
{ alert( "Please provide a zip in the format #####." ); document.myForm.Zip.focus()
; return false; }
JavaScript form validation example
if( document.myForm.Country.value == "-1" )
{
alert( "Please provide your country!" );
return false; }
var emailID = document.myForm.EMail.value;
atpos = emailID.indexOf("@");
dotpos = emailID.lastIndexOf(".");
JavaScript form validation example
if (atpos < 1 || ( dotpos - atpos < 2 ))
{
alert("Please enter correct email ID")
document.myForm.EMail.focus() ;
return false; }
return( true );
}
</script>
</head>
JavaScript form validation example
<body>
<form action="/cgi-bin/test.cgi" name="myForm" onsubmit="return(validate());">
<table cellspacing="2" cellpadding="2" border="1">
<tr> <td align="right">Name</td>
<td><input type="text" name="Name" /></td> </tr>
<tr> <td align="right">EMail</td>
<td><input type="text" name="EMail" /></td> </tr>
JavaScript form validation example
<tr> <td align="right">Zip Code</td>
<td><input type="text" name="Zip" /></td> </tr>
<tr> <td align="right">Country</td>
<td> <select name="Country">
<option value="-1" selected>[choose yours] </option>
<option value="1">USA</option>
<option value="2">UK</option>
<option value="3">INDIA</option>
</select> </td> </tr>
JavaScript form validation example
<tr> <td align="right"></td>
<td><input type="submit" value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>
JavaScript form validation example
Thank You

More Related Content

PPTX
Form Validation in JavaScript
Ravi Bhadauria
 
PPTX
Html form tag
shreyachougule
 
PPTX
Html forms
Himanshu Pathak
 
PPT
Html forms
M Vishnuvardhan Reddy
 
PPT
Php forms
Anne Lee
 
PDF
Php Tutorials for Beginners
Vineet Kumar Saini
 
PDF
JavaScript - Chapter 14 - Form Handling
WebStackAcademy
 
Form Validation in JavaScript
Ravi Bhadauria
 
Html form tag
shreyachougule
 
Html forms
Himanshu Pathak
 
Php forms
Anne Lee
 
Php Tutorials for Beginners
Vineet Kumar Saini
 
JavaScript - Chapter 14 - Form Handling
WebStackAcademy
 

What's hot (20)

PPT
Java Script ppt
Priya Goyal
 
PDF
javascript objects
Vijay Kalyan
 
PPTX
Javascript validating form
Jesus Obenita Jr.
 
PPTX
PHP FUNCTIONS
Zeeshan Ahmed
 
PPT
Css Ppt
Hema Prasanth
 
PDF
Html forms
eShikshak
 
PPTX
Event In JavaScript
ShahDhruv21
 
PDF
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
WebStackAcademy
 
PPSX
Javascript variables and datatypes
Varun C M
 
PPSX
Php and MySQL
Tiji Thomas
 
PPTX
Html5 semantics
Webtech Learning
 
PPT
PHP - Introduction to PHP Forms
Vibrant Technologies & Computers
 
PPTX
Document Object Model (DOM)
GOPAL BASAK
 
PPS
String and string buffer
kamal kotecha
 
PDF
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
PPTX
Arrays in Java
Abhilash Nair
 
PPT
Introduction to JavaScript
Andres Baravalle
 
PDF
JavaScript Programming
Sehwan Noh
 
PPT
Oops concepts in php
CPD INDIA
 
Java Script ppt
Priya Goyal
 
javascript objects
Vijay Kalyan
 
Javascript validating form
Jesus Obenita Jr.
 
PHP FUNCTIONS
Zeeshan Ahmed
 
Css Ppt
Hema Prasanth
 
Html forms
eShikshak
 
Event In JavaScript
ShahDhruv21
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
WebStackAcademy
 
Javascript variables and datatypes
Varun C M
 
Php and MySQL
Tiji Thomas
 
Html5 semantics
Webtech Learning
 
PHP - Introduction to PHP Forms
Vibrant Technologies & Computers
 
Document Object Model (DOM)
GOPAL BASAK
 
String and string buffer
kamal kotecha
 
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
Arrays in Java
Abhilash Nair
 
Introduction to JavaScript
Andres Baravalle
 
JavaScript Programming
Sehwan Noh
 
Oops concepts in php
CPD INDIA
 
Ad

Similar to Form using html and java script validation (20)

PPTX
HYPERTEXT MARK UP LANGUAGES (HTML) FORMS
RoselAAliganga
 
PPTX
HTML Forms
bismakhan12
 
PPTX
html forms
ikram niaz
 
PPT
05 html-forms
Palakshya
 
PDF
Getting Information through HTML Forms
Mike Crabb
 
DOCX
Html forms
Abhishek Kesharwani
 
PPT
20 html-forms
Kumar
 
PDF
2. HTML forms
Pavle Đorđević
 
PPT
20-html-forms.ppt
KarenCato1
 
PPTX
Web topic 22 validation on web forms
CK Yang
 
PPSX
Computer language - Html forms
Dr. I. Uma Maheswari Maheswari
 
PPT
11-html-forms.ppt
karansingh4126
 
KEY
HTML5 Form Validation
Ian Oxley
 
PPTX
Html forms
KoreshPadhi
 
PPT
Forms,Frames.ppt
MaheShiva
 
PPT
Forms,Frames.ppt
MaheShiva
 
PPTX
1. Lecture 1 WT- Forms.pptxl;kjhgfdsfghj
tavgaqasim8
 
PPTX
Html forms
Er. Nawaraj Bhandari
 
PPTX
lecture9-10-160807085530.pptx dgdg fdgdfv ds
drpreetiwctm
 
HYPERTEXT MARK UP LANGUAGES (HTML) FORMS
RoselAAliganga
 
HTML Forms
bismakhan12
 
html forms
ikram niaz
 
05 html-forms
Palakshya
 
Getting Information through HTML Forms
Mike Crabb
 
20 html-forms
Kumar
 
2. HTML forms
Pavle Đorđević
 
20-html-forms.ppt
KarenCato1
 
Web topic 22 validation on web forms
CK Yang
 
Computer language - Html forms
Dr. I. Uma Maheswari Maheswari
 
11-html-forms.ppt
karansingh4126
 
HTML5 Form Validation
Ian Oxley
 
Html forms
KoreshPadhi
 
Forms,Frames.ppt
MaheShiva
 
Forms,Frames.ppt
MaheShiva
 
1. Lecture 1 WT- Forms.pptxl;kjhgfdsfghj
tavgaqasim8
 
lecture9-10-160807085530.pptx dgdg fdgdfv ds
drpreetiwctm
 
Ad

More from Maitree Patel (11)

PPTX
MACs based on Hash Functions, MACs based on Block Ciphers
Maitree Patel
 
PPT
Software engineering Testing technique,test case,test suit design
Maitree Patel
 
PPTX
Dotnet :Attributes
Maitree Patel
 
PPTX
Advance Java
Maitree Patel
 
PPTX
Introduction of Memory Management
Maitree Patel
 
PPTX
Scheduling Definition, objectives and types
Maitree Patel
 
PPTX
Simple Mail Transfer Protocol
Maitree Patel
 
PPTX
Virtual circuit and Datagram network
Maitree Patel
 
PPTX
Gauss Quadrature Formula
Maitree Patel
 
PPT
Merge sort and Quick sort
Maitree Patel
 
PPTX
Static Import and access modifiers
Maitree Patel
 
MACs based on Hash Functions, MACs based on Block Ciphers
Maitree Patel
 
Software engineering Testing technique,test case,test suit design
Maitree Patel
 
Dotnet :Attributes
Maitree Patel
 
Advance Java
Maitree Patel
 
Introduction of Memory Management
Maitree Patel
 
Scheduling Definition, objectives and types
Maitree Patel
 
Simple Mail Transfer Protocol
Maitree Patel
 
Virtual circuit and Datagram network
Maitree Patel
 
Gauss Quadrature Formula
Maitree Patel
 
Merge sort and Quick sort
Maitree Patel
 
Static Import and access modifiers
Maitree Patel
 

Recently uploaded (20)

PDF
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
PDF
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
PPTX
Information Retrieval and Extraction - Module 7
premSankar19
 
PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
PDF
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
PDF
Construction of a Thermal Vacuum Chamber for Environment Test of Triple CubeS...
2208441
 
PDF
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
PPTX
sunil mishra pptmmmmmmmmmmmmmmmmmmmmmmmmm
singhamit111
 
PPTX
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
PDF
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
PDF
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
PDF
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
PPTX
quantum computing transition from classical mechanics.pptx
gvlbcy
 
PPTX
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
PPT
Understanding the Key Components and Parts of a Drone System.ppt
Siva Reddy
 
PDF
20ME702-Mechatronics-UNIT-1,UNIT-2,UNIT-3,UNIT-4,UNIT-5, 2025-2026
Mohanumar S
 
PPTX
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
PDF
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
Information Retrieval and Extraction - Module 7
premSankar19
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
Construction of a Thermal Vacuum Chamber for Environment Test of Triple CubeS...
2208441
 
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
sunil mishra pptmmmmmmmmmmmmmmmmmmmmmmmmm
singhamit111
 
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
quantum computing transition from classical mechanics.pptx
gvlbcy
 
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
Understanding the Key Components and Parts of a Drone System.ppt
Siva Reddy
 
20ME702-Mechatronics-UNIT-1,UNIT-2,UNIT-3,UNIT-4,UNIT-5, 2025-2026
Mohanumar S
 
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 

Form using html and java script validation

  • 1. VADODARA INSTITUTE OF ENGINEERING ACTIVE LEARNING ASSIGNMENT Web Technology (2160708) TOPIC : Form using HTML and Java scripts with validation Presented By: Kashyap Patel 150800107046 Krishna Patel 150800107047 Maitree Patel 150800107048 :
  • 2. Content  HTML Forms • Introduction • The <input> Element • HTML Form Controls • Form Attribute Java script with validation • Why do we need validation • JavaScript form validation example
  • 3. HTML Forms Introduction : • HTML Forms are required when some data needs to be collected. • For example during registration information like name, email-id, address etc. • A Form will take input form the site visitor and then post into a backend application. • It will perform require processing on the pass data based on defined business logic inside application.
  • 4. Introduction • The HTML <form> element defines a form that is used to collect user input: • <form> . form elements . </form> • An HTML form contains form elements. • Form elements are different types of input elements, like text fields, checkboxes, radio buttons, submit buttons, and more.
  • 5. The <input> Element • The <input> element is the most important form element. • The <input> element can be displayed in several ways, depending on the type attribute. • Here are some examples: Type Description <input type="text"> Defines a one-line text input field <input type="radio"> Defines a radio button (for selecting one of many choices) <input type="submit"> Defines a submit button (for submitting the form)
  • 6. HTML Form Controls 1. Text Input There are 3 types of text input control used on forms. • Single line Text Input control <form> First name:<br> <input type="text" name="firstname"><br> </form> file:///D:/wt/new%201.html
  • 7. HTML Form Controls • Password Input Control This also single line Text input but it makes characters as soon as user enter it. Ex.Password < input type = “Password” name=“password”/>
  • 8. HTML Form Controls • Multiple line Input Control This is used when user is required to give details that may be longer than single sentence. ex. <textarea rows = “3” cols = “5” >
  • 9. HTML Form Controls 2. Checkbox Control It is used when more than one option is required to be selected. Ex. <input type = "checkbox" name = "maths" checked>maths<br> <input type = "checkbox" name = "wt" uchecked>wt<br>
  • 10. HTML Form Controls 3. Radio Button Radio buttons are used when out of many options just one option is required to be selected. • Ex<form> <input type="radio" name="gender" value="male" checked> Male<br> <input type="radio" name="gender" value="female"> Female<br> <input type="radio" name="gender" value="other"> Other </form>
  • 11. HTML Form Controls 4. Select box Control (Drop down Box) It provide <option> tag to list out various option in form of drop down list. Ex. <select name=“Subject”> <option value=“maths”>maths</option> <option value=“physics”>physics</option> <option value=“chemistry”>chemistry</option>
  • 12. HTML Form Controls 5. File upload box If you want to allow user to upload the file used file upload box. Name and accept are attribute. Ex.<input type=“file" name=“upload" accept= “jpg.doc”/>
  • 13. HTML Form Controls 6. Button controls • Submit Button : This creates a button that automatically submits a form. Ex. <form> First name:<br> <input type="text" value="Mickey"><br> Last name:<br> <input type="text" name="lastname" value="Mouse"><br><br> <input type="submit" value="Submit"> </form>
  • 14. HTML Form Controls • Reset Button: This creates a button that automatically reset form controls to their initial value. Ex. First Name:<br> <input type="text" name=“First Name”><br> Last Name<br> <input type="text" name=“Last Name" ><br><br> <input type="submit" value="Submit"> <input type=“reset" value=“Reset">
  • 15. HTML Form Controls • Button : This creates a button that is used to trigger client side script when the user click that button. Ex. <input type=“button" value=“button"> • Image : This creates a clickable button but we can used ad image as background of the button. Ex. <input type = “image" src = "pexels-photo-547114.jpeg">
  • 16. Form Attributes 1. The Action Attribute • The action attribute defines the action to be performed when the form is submitted. • Normally, the form data is sent to a web page on the server when the user clicks on the submit button. Ex. <form action="/action_page.php"> 2. The Name Attribute • Each input field must have a name attribute to be submitted. • If the name attribute is omitted, the data of that input field will not be sent at all.
  • 17. Form Attributes 3. The Method attribute • It specifies how to send form data. • The form data is send to the page specified in the action attribute. Ex. <form action="/action_page.php" method="get"> • when GET is used, the submitted form data will be visible in the page address field: /action_page.php?firstname=Mickey&lastname=Mouse Ex. <form action="/action_page.php" method="post"> • POST if the form data contains sensitive or personal information. The POST method does not display the submitted form data in the page address field.
  • 18. Form Attributes 4. The Target Attribute • The target attribute specifies if the submitted result will open in a new browser tab, a frame, or in the current window. • _blank : the response is display in new window or tab. • _self : the response is displayed in same frame. • _parent : the response is displayed in parent frame. • _top : display full body of the window. • _framename : display in name frame.
  • 19. Java script with validation • It is important to validate the form submitted by the user because it can have inappropriate values. So validation is must. • The JavaScript provides you the facility the validate the form on the client side so processing will be fast than server-side validation. So, most of the web developers prefer JavaScript form validation. • Through JavaScript, we can validate name, password, email, date, mobile number etc fields.
  • 20. JavaScript form validation example <html><body> <script> function validateform(){ var name=document.myform.name.value; var password=document.myform.password.value; if (name==null || name==""){ alert("Name can't be blank"); return false; } else if(password.length<6){ alert("Password must be at least 6 characters long."); return false; } } </script>
  • 21. JavaScript form validation example <body> <form name="myform" method="post" action="abc.jsp" onsubmit="return validatef orm()" > Name: <input type="text" name="name"><br/> Password: <input type="password" name="password"><br/> <input type="submit" value="register"> </form>
  • 22. JavaScript form validation example <html> <head> <title>Form Validation</title> <script ty pe="text/javascript"> </script> function validate() { if( document.myForm.Name.value == "" ) { alert( "Please provide your name!" ); document.myForm.Name.focus() ; return false; }
  • 23. JavaScript form validation example if( document.myForm.EMail.value == "" ) { alert( "Please provide your Email!" ); Document.myForm.EMail.focus() ; return false; } if( document.myForm.Zip.value == "" || isNaN(document.myForm.Zip.value ) || document.myForm.Zip.value.length != 5 ) { alert( "Please provide a zip in the format #####." ); document.myForm.Zip.focus() ; return false; }
  • 24. JavaScript form validation example if( document.myForm.Country.value == "-1" ) { alert( "Please provide your country!" ); return false; } var emailID = document.myForm.EMail.value; atpos = emailID.indexOf("@"); dotpos = emailID.lastIndexOf(".");
  • 25. JavaScript form validation example if (atpos < 1 || ( dotpos - atpos < 2 )) { alert("Please enter correct email ID") document.myForm.EMail.focus() ; return false; } return( true ); } </script> </head>
  • 26. JavaScript form validation example <body> <form action="/cgi-bin/test.cgi" name="myForm" onsubmit="return(validate());"> <table cellspacing="2" cellpadding="2" border="1"> <tr> <td align="right">Name</td> <td><input type="text" name="Name" /></td> </tr> <tr> <td align="right">EMail</td> <td><input type="text" name="EMail" /></td> </tr>
  • 27. JavaScript form validation example <tr> <td align="right">Zip Code</td> <td><input type="text" name="Zip" /></td> </tr> <tr> <td align="right">Country</td> <td> <select name="Country"> <option value="-1" selected>[choose yours] </option> <option value="1">USA</option> <option value="2">UK</option> <option value="3">INDIA</option> </select> </td> </tr>
  • 28. JavaScript form validation example <tr> <td align="right"></td> <td><input type="submit" value="Submit" /></td> </tr> </table> </form> </body> </html>