SlideShare a Scribd company logo
Form Validation A Simple Javascript Exercise
Sending eMessages A alternative to email Message is stored in company database But how do we check that the requires fields are filled in? Do this at the client side using javascript
The Form Six fields – the first four are of type="text", the fifth is a drop down selectlistbox, and the last is a textarea. Note that the submit button is disabled.
The XHTML Markup #1 <body>  <imgsrc="bdlogo.gif“  />  <form id="emessage" method="post" action="msgadd.php">  <fieldset style="border:none"> ……….  </fieldset> </body> First, the image, form and fieldset tags. Remember that the XHTML  Strict doctype requires all form elements to be contained inside a fieldset or similar structure . Note also that the name attribute is not used in the form tag, instead we use id.
The XHTML Markup #2 <body> <form id="emessage" method="post" action="msgadd.php"> <fieldset style="border:none">  ……. <label for="name">Name: </label>  <input type="text" name="name" id="name" onclick="enable()" style="width:240" /><span style="color:red"> * </span><br />  <label for="email">Email: </label>  <input type="text" name="email" id="email" style="width:240"/><span style="color:red"> * </span><br />  <label for="phone">Telephone No: </label>  <input type="text" name="phone" id="phone" style="width:140" /><br />  <label for="sales">Sales/Returns<br />Order No: </label>  <input type="text" name="sales" id="sales" style="width:100" /><br /> ………  </fieldset> </form> </body> Next, the labels and input fields of type="text“. Note the onclick event handler called enable() in the name field – more on this later
The XHTML Markup #3 <body> <form id="emessage" method="post" action="msgadd.php"> <fieldset style="border:none">  ……. <label for="enq">Nature of<br />Enquiry: </label> <select name="enq" id="enq" style="width:240" />   <option value="0">Please Select</option>   <option value="Defective Goods">Defective Goods</option>   <option value="Missing Items">Missing Items</option>    <option value="Non-Delivery">Non-Delivery</option>  </select><span style="color:red"> * </span><br /><br />  ………  </fieldset> </form> </body> Next, the label and drop down selectlistbox
The XHTML Markup #4 <body> <form id="emessage" method="post" action="msgadd.php"> <fieldset style="border:none">  …….  <label for="message">Message: </label>  <textarea rows="20" cols="60" name="message" id="message"></textarea><span style="color:red"> * </span><br />     <br />  <input type="submit" name="submit" id="submit" value="Send" disabled="disabled" onclick="return checkmessages()" />   <input type="reset" name="reset" id="reset" value="Reset" /> ………  </fieldset> </form> </body> Last, the textareaand submit and reset buttons. Note that the submit button is initially disabled. Note also it’s onclick event handler – we use this to check that the form fields are filled in as required
The Required Fields There are four required fields on the form marked with a red asterix (*) When the user clicks the submit button we need to check that they have all been filled in We do this using a javascript function called checkmessages() This is invoked when the user clicks the submit button Our javascript code goes in the <head> section of the document and must be enclosed in <script> .. </script> tags When the user clicks in the name field the submit button will be enabled.
The enable() Function function enable() { document.getElementById("emessage").submit.disabled=false; } This is the code that enables the submit button once the user clicks in the name field. Note the use of the document.getElementById() function – this is our way of accessing the form elements.
The checkmessages() Function function checkmessages() { vartheMessage = "Invalid Message - Please complete the following: ------------------------------------------------------------------------"; varnoErrors = true;    if (document.getElementById("emessage").name.value=="") { theMessage = theMessage + " --> Name"; noErrors = false;    }    // If no errors, submit the form    if (noErrors) {       return true;    } else {     // errors were found, show alert message     alert(theMessage); document.getElementById("emessage").submit.disabled=true;     return false;    }  } // end of function checkmessages() This is the code that checks the name field. To check the remaining fields you only need copy and paste this and edit  the name of the field being checked. For the select field however you will need to check if the value is "0"
Styling the Form To pretty up the form we use a style sheet: <style>  label{   float: left;   width: 180px;   font-weight: bold;  } textarea,select,input{  margin-bottom: 5px;  }  #submit{  margin-left: 200px;  margin-top: 5px;  width: 100px; } br{  clear: left; } </style>
Warning the User If a required field is not filled in we output a warning message to this effect on the screen Let’s assume the name field isn’t filled in.
Confirming Form Submission Once the form has been successfully submitted we need to inform the user of this This can be done with a simple php script (see next slide).
Success!

More Related Content

What's hot

WP7 HUB_Diseño del interfaz con Silverlight
WP7 HUB_Diseño del interfaz con SilverlightWP7 HUB_Diseño del interfaz con Silverlight
WP7 HUB_Diseño del interfaz con Silverlight
MICTT Palma
 
Php Form
Php FormPhp Form
Php Form
lotlot
 
Entering User Data from a Web Page HTML Forms
Entering User Data from a Web Page HTML FormsEntering User Data from a Web Page HTML Forms
Entering User Data from a Web Page HTML Forms
sathish sak
 
Web engineering - HTML Form
Web engineering -  HTML FormWeb engineering -  HTML Form
Web engineering - HTML Form
Nosheen Qamar
 
PHP Making Web Forms
PHP Making Web FormsPHP Making Web Forms
PHP Making Web Forms
krishnapriya Tadepalli
 
HTML 5 Simple Tutorial Part 4
HTML 5 Simple Tutorial Part 4HTML 5 Simple Tutorial Part 4
HTML 5 Simple Tutorial Part 4
Sanjeev Kumar
 
HTML::FormFu talk for Sydney PM
HTML::FormFu talk for Sydney PMHTML::FormFu talk for Sydney PM
HTML::FormFu talk for Sydney PM
Dean Hamstead
 
Building a Blogging System -- Rapidly using Alpha Five v10 with Codeless AJAX...
Building a Blogging System -- Rapidly using Alpha Five v10 with Codeless AJAX...Building a Blogging System -- Rapidly using Alpha Five v10 with Codeless AJAX...
Building a Blogging System -- Rapidly using Alpha Five v10 with Codeless AJAX...
Richard Rabins
 
JavaScript Training in Ambala ! Batra Computer Centre
JavaScript Training in Ambala ! Batra Computer CentreJavaScript Training in Ambala ! Batra Computer Centre
JavaScript Training in Ambala ! Batra Computer Centre
jatin batra
 
Acceptance Testing With Selenium
Acceptance Testing With SeleniumAcceptance Testing With Selenium
Acceptance Testing With Selenium
elliando dias
 
Exception handling
Exception handlingException handling
Exception handling
Mahesh Pachbhai
 
phptut2
phptut2phptut2
phptut2
tutorialsruby
 
Php and web forms
Php and web formsPhp and web forms
Php and web forms
sana mateen
 
e computer notes - Creating views
e computer notes - Creating viewse computer notes - Creating views
e computer notes - Creating views
ecomputernotes
 
Access tips access and sql part 5 more instant queries 1
Access tips  access and sql part 5  more instant queries 1Access tips  access and sql part 5  more instant queries 1
Access tips access and sql part 5 more instant queries 1
quest2900
 
Esd input inplace
Esd input inplaceEsd input inplace
Esd input inplace
Anumadil1
 
Mechanize at the Ruby Drink-up of Sophia, November 2011
Mechanize at the Ruby Drink-up of Sophia, November 2011Mechanize at the Ruby Drink-up of Sophia, November 2011
Mechanize at the Ruby Drink-up of Sophia, November 2011
rivierarb
 
Html4
Html4Html4

What's hot (18)

WP7 HUB_Diseño del interfaz con Silverlight
WP7 HUB_Diseño del interfaz con SilverlightWP7 HUB_Diseño del interfaz con Silverlight
WP7 HUB_Diseño del interfaz con Silverlight
 
Php Form
Php FormPhp Form
Php Form
 
Entering User Data from a Web Page HTML Forms
Entering User Data from a Web Page HTML FormsEntering User Data from a Web Page HTML Forms
Entering User Data from a Web Page HTML Forms
 
Web engineering - HTML Form
Web engineering -  HTML FormWeb engineering -  HTML Form
Web engineering - HTML Form
 
PHP Making Web Forms
PHP Making Web FormsPHP Making Web Forms
PHP Making Web Forms
 
HTML 5 Simple Tutorial Part 4
HTML 5 Simple Tutorial Part 4HTML 5 Simple Tutorial Part 4
HTML 5 Simple Tutorial Part 4
 
HTML::FormFu talk for Sydney PM
HTML::FormFu talk for Sydney PMHTML::FormFu talk for Sydney PM
HTML::FormFu talk for Sydney PM
 
Building a Blogging System -- Rapidly using Alpha Five v10 with Codeless AJAX...
Building a Blogging System -- Rapidly using Alpha Five v10 with Codeless AJAX...Building a Blogging System -- Rapidly using Alpha Five v10 with Codeless AJAX...
Building a Blogging System -- Rapidly using Alpha Five v10 with Codeless AJAX...
 
JavaScript Training in Ambala ! Batra Computer Centre
JavaScript Training in Ambala ! Batra Computer CentreJavaScript Training in Ambala ! Batra Computer Centre
JavaScript Training in Ambala ! Batra Computer Centre
 
Acceptance Testing With Selenium
Acceptance Testing With SeleniumAcceptance Testing With Selenium
Acceptance Testing With Selenium
 
Exception handling
Exception handlingException handling
Exception handling
 
phptut2
phptut2phptut2
phptut2
 
Php and web forms
Php and web formsPhp and web forms
Php and web forms
 
e computer notes - Creating views
e computer notes - Creating viewse computer notes - Creating views
e computer notes - Creating views
 
Access tips access and sql part 5 more instant queries 1
Access tips  access and sql part 5  more instant queries 1Access tips  access and sql part 5  more instant queries 1
Access tips access and sql part 5 more instant queries 1
 
Esd input inplace
Esd input inplaceEsd input inplace
Esd input inplace
 
Mechanize at the Ruby Drink-up of Sophia, November 2011
Mechanize at the Ruby Drink-up of Sophia, November 2011Mechanize at the Ruby Drink-up of Sophia, November 2011
Mechanize at the Ruby Drink-up of Sophia, November 2011
 
Html4
Html4Html4
Html4
 

Viewers also liked

Javascript validating form
Javascript validating formJavascript validating form
Javascript validating form
Jesus Obenita Jr.
 
Javascript validation karan chanana
Javascript validation karan chananaJavascript validation karan chanana
Javascript validation karan chanana
karanchanan
 
Javascript validation assignment
Javascript validation assignmentJavascript validation assignment
Javascript validation assignment
H K
 
02. input validation module v5
02. input validation module v502. input validation module v5
02. input validation module v5
Eoin Keary
 
1 - Designing A Site
1 - Designing A Site1 - Designing A Site
1 - Designing A Site
Graeme Smith
 
Accessible dynamic forms
Accessible dynamic formsAccessible dynamic forms
Accessible dynamic forms
Dylan Barrell
 
Web forms and server side scripting
Web forms and server side scriptingWeb forms and server side scripting
Web forms and server side scripting
sawsan slii
 
Ch3 server controls
Ch3 server controlsCh3 server controls
Ch3 server controls
Madhuri Kavade
 
Javascript
JavascriptJavascript
Javascript
Nagarajan
 
Java script ppt
Java script pptJava script ppt
Javascript Best Practices
Javascript Best PracticesJavascript Best Practices
Javascript Best Practices
Christian Heilmann
 

Viewers also liked (11)

Javascript validating form
Javascript validating formJavascript validating form
Javascript validating form
 
Javascript validation karan chanana
Javascript validation karan chananaJavascript validation karan chanana
Javascript validation karan chanana
 
Javascript validation assignment
Javascript validation assignmentJavascript validation assignment
Javascript validation assignment
 
02. input validation module v5
02. input validation module v502. input validation module v5
02. input validation module v5
 
1 - Designing A Site
1 - Designing A Site1 - Designing A Site
1 - Designing A Site
 
Accessible dynamic forms
Accessible dynamic formsAccessible dynamic forms
Accessible dynamic forms
 
Web forms and server side scripting
Web forms and server side scriptingWeb forms and server side scripting
Web forms and server side scripting
 
Ch3 server controls
Ch3 server controlsCh3 server controls
Ch3 server controls
 
Javascript
JavascriptJavascript
Javascript
 
Java script ppt
Java script pptJava script ppt
Java script ppt
 
Javascript Best Practices
Javascript Best PracticesJavascript Best Practices
Javascript Best Practices
 

Similar to Form Validation

Lecture 2 - Comm Lab: Web @ ITP
Lecture 2 - Comm Lab: Web @ ITPLecture 2 - Comm Lab: Web @ ITP
Lecture 2 - Comm Lab: Web @ ITP
yucefmerhi
 
We9 Struts 2.0
We9 Struts 2.0We9 Struts 2.0
We9 Struts 2.0
wangjiaz
 
Quick Referance to WML
Quick Referance to WMLQuick Referance to WML
Quick Referance to WML
Nitin Saswade
 
Lecture3
Lecture3Lecture3
Grddl In A Nutshell V1
Grddl In A Nutshell V1Grddl In A Nutshell V1
Grddl In A Nutshell V1
Fabien Gandon
 
KMUTNB - Internet Programming 3/7
KMUTNB - Internet Programming 3/7KMUTNB - Internet Programming 3/7
KMUTNB - Internet Programming 3/7
phuphax
 
Ajax ons2
Ajax ons2Ajax ons2
Ajax ons2
Chad Davis
 
Zend Form Tutorial
Zend Form TutorialZend Form Tutorial
Zend Form Tutorial
Michelangelo van Dam
 
JSP Custom Tags
JSP Custom TagsJSP Custom Tags
JSP Custom Tags
BG Java EE Course
 
Java Script
Java ScriptJava Script
Java Script
siddaram
 
Lecture1 B Frames&Forms
Lecture1 B  Frames&FormsLecture1 B  Frames&Forms
Lecture1 B Frames&Forms
Sur College of Applied Sciences
 
Neil Patel - What You Need to be Measuring and How to Do It
Neil Patel - What You Need to be Measuring and How to Do ItNeil Patel - What You Need to be Measuring and How to Do It
Neil Patel - What You Need to be Measuring and How to Do It
Carsonified Team
 
Developing and testing ajax components
Developing and testing ajax componentsDeveloping and testing ajax components
Developing and testing ajax components
Ignacio Coloma
 
Widgets Tools Keynote
Widgets Tools KeynoteWidgets Tools Keynote
Widgets Tools Keynote
Michael Mahemoff
 
Php Calling Operators
Php Calling OperatorsPhp Calling Operators
Php Calling Operators
mussawir20
 
From "Username and Password" to InfoCard
From "Username and Password" to InfoCardFrom "Username and Password" to InfoCard
From "Username and Password" to InfoCard
goodfriday
 
SES Chicago "Developments in Information Retrieval on the Web"
SES Chicago "Developments in Information Retrieval on the Web"SES Chicago "Developments in Information Retrieval on the Web"
SES Chicago "Developments in Information Retrieval on the Web"
Jay Myers
 
Lecture 5 - Comm Lab: Web @ ITP
Lecture 5 - Comm Lab: Web @ ITPLecture 5 - Comm Lab: Web @ ITP
Lecture 5 - Comm Lab: Web @ ITP
yucefmerhi
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
mussawir20
 
YQL talk at OHD Jakarta
YQL talk at OHD JakartaYQL talk at OHD Jakarta
YQL talk at OHD Jakarta
Michael Smith Jr.
 

Similar to Form Validation (20)

Lecture 2 - Comm Lab: Web @ ITP
Lecture 2 - Comm Lab: Web @ ITPLecture 2 - Comm Lab: Web @ ITP
Lecture 2 - Comm Lab: Web @ ITP
 
We9 Struts 2.0
We9 Struts 2.0We9 Struts 2.0
We9 Struts 2.0
 
Quick Referance to WML
Quick Referance to WMLQuick Referance to WML
Quick Referance to WML
 
Lecture3
Lecture3Lecture3
Lecture3
 
Grddl In A Nutshell V1
Grddl In A Nutshell V1Grddl In A Nutshell V1
Grddl In A Nutshell V1
 
KMUTNB - Internet Programming 3/7
KMUTNB - Internet Programming 3/7KMUTNB - Internet Programming 3/7
KMUTNB - Internet Programming 3/7
 
Ajax ons2
Ajax ons2Ajax ons2
Ajax ons2
 
Zend Form Tutorial
Zend Form TutorialZend Form Tutorial
Zend Form Tutorial
 
JSP Custom Tags
JSP Custom TagsJSP Custom Tags
JSP Custom Tags
 
Java Script
Java ScriptJava Script
Java Script
 
Lecture1 B Frames&Forms
Lecture1 B  Frames&FormsLecture1 B  Frames&Forms
Lecture1 B Frames&Forms
 
Neil Patel - What You Need to be Measuring and How to Do It
Neil Patel - What You Need to be Measuring and How to Do ItNeil Patel - What You Need to be Measuring and How to Do It
Neil Patel - What You Need to be Measuring and How to Do It
 
Developing and testing ajax components
Developing and testing ajax componentsDeveloping and testing ajax components
Developing and testing ajax components
 
Widgets Tools Keynote
Widgets Tools KeynoteWidgets Tools Keynote
Widgets Tools Keynote
 
Php Calling Operators
Php Calling OperatorsPhp Calling Operators
Php Calling Operators
 
From "Username and Password" to InfoCard
From "Username and Password" to InfoCardFrom "Username and Password" to InfoCard
From "Username and Password" to InfoCard
 
SES Chicago "Developments in Information Retrieval on the Web"
SES Chicago "Developments in Information Retrieval on the Web"SES Chicago "Developments in Information Retrieval on the Web"
SES Chicago "Developments in Information Retrieval on the Web"
 
Lecture 5 - Comm Lab: Web @ ITP
Lecture 5 - Comm Lab: Web @ ITPLecture 5 - Comm Lab: Web @ ITP
Lecture 5 - Comm Lab: Web @ ITP
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
 
YQL talk at OHD Jakarta
YQL talk at OHD JakartaYQL talk at OHD Jakarta
YQL talk at OHD Jakarta
 

More from Graeme Smith

Project Management - An Introductiuon
Project Management - An IntroductiuonProject Management - An Introductiuon
Project Management - An Introductiuon
Graeme Smith
 
Intro to the unit
Intro to the unitIntro to the unit
Intro to the unit
Graeme Smith
 
The CSS Box Model
The CSS Box ModelThe CSS Box Model
The CSS Box Model
Graeme Smith
 
The art of presentations
The art of presentationsThe art of presentations
The art of presentations
Graeme Smith
 
Typography, A Presentation
Typography, A PresentationTypography, A Presentation
Typography, A Presentation
Graeme Smith
 
Flip Book
Flip BookFlip Book
Flip Book
Graeme Smith
 
Typography
TypographyTypography
Typography
Graeme Smith
 
Typography and grids
Typography and gridsTypography and grids
Typography and grids
Graeme Smith
 
Intro to Game Design
Intro to Game DesignIntro to Game Design
Intro to Game Design
Graeme Smith
 
Composition, some basic rules of photography
Composition, some basic rules of photographyComposition, some basic rules of photography
Composition, some basic rules of photography
Graeme Smith
 
Personality Emotion
Personality EmotionPersonality Emotion
Personality Emotion
Graeme Smith
 
Personality Emotion
Personality EmotionPersonality Emotion
Personality Emotion
Graeme Smith
 
Information Design
Information DesignInformation Design
Information Design
Graeme Smith
 
Perspective Principles
Perspective PrinciplesPerspective Principles
Perspective Principles
Graeme Smith
 
Interaction Design
Interaction DesignInteraction Design
Interaction Design
Graeme Smith
 
Colour
ColourColour
Colour
Graeme Smith
 
Web Functionality
Web FunctionalityWeb Functionality
Web Functionality
Graeme Smith
 
Layout Principles
Layout PrinciplesLayout Principles
Layout Principles
Graeme Smith
 
Layout Principles 1
Layout Principles 1Layout Principles 1
Layout Principles 1
Graeme Smith
 
Content for the Web
Content for the WebContent for the Web
Content for the Web
Graeme Smith
 

More from Graeme Smith (20)

Project Management - An Introductiuon
Project Management - An IntroductiuonProject Management - An Introductiuon
Project Management - An Introductiuon
 
Intro to the unit
Intro to the unitIntro to the unit
Intro to the unit
 
The CSS Box Model
The CSS Box ModelThe CSS Box Model
The CSS Box Model
 
The art of presentations
The art of presentationsThe art of presentations
The art of presentations
 
Typography, A Presentation
Typography, A PresentationTypography, A Presentation
Typography, A Presentation
 
Flip Book
Flip BookFlip Book
Flip Book
 
Typography
TypographyTypography
Typography
 
Typography and grids
Typography and gridsTypography and grids
Typography and grids
 
Intro to Game Design
Intro to Game DesignIntro to Game Design
Intro to Game Design
 
Composition, some basic rules of photography
Composition, some basic rules of photographyComposition, some basic rules of photography
Composition, some basic rules of photography
 
Personality Emotion
Personality EmotionPersonality Emotion
Personality Emotion
 
Personality Emotion
Personality EmotionPersonality Emotion
Personality Emotion
 
Information Design
Information DesignInformation Design
Information Design
 
Perspective Principles
Perspective PrinciplesPerspective Principles
Perspective Principles
 
Interaction Design
Interaction DesignInteraction Design
Interaction Design
 
Colour
ColourColour
Colour
 
Web Functionality
Web FunctionalityWeb Functionality
Web Functionality
 
Layout Principles
Layout PrinciplesLayout Principles
Layout Principles
 
Layout Principles 1
Layout Principles 1Layout Principles 1
Layout Principles 1
 
Content for the Web
Content for the WebContent for the Web
Content for the Web
 

Recently uploaded

“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
Neo4j
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 

Recently uploaded (20)

“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 

Form Validation

  • 1. Form Validation A Simple Javascript Exercise
  • 2. Sending eMessages A alternative to email Message is stored in company database But how do we check that the requires fields are filled in? Do this at the client side using javascript
  • 3. The Form Six fields – the first four are of type="text", the fifth is a drop down selectlistbox, and the last is a textarea. Note that the submit button is disabled.
  • 4. The XHTML Markup #1 <body> <imgsrc="bdlogo.gif“ /> <form id="emessage" method="post" action="msgadd.php"> <fieldset style="border:none"> ………. </fieldset> </body> First, the image, form and fieldset tags. Remember that the XHTML Strict doctype requires all form elements to be contained inside a fieldset or similar structure . Note also that the name attribute is not used in the form tag, instead we use id.
  • 5. The XHTML Markup #2 <body> <form id="emessage" method="post" action="msgadd.php"> <fieldset style="border:none"> ……. <label for="name">Name: </label> <input type="text" name="name" id="name" onclick="enable()" style="width:240" /><span style="color:red"> * </span><br /> <label for="email">Email: </label> <input type="text" name="email" id="email" style="width:240"/><span style="color:red"> * </span><br /> <label for="phone">Telephone No: </label> <input type="text" name="phone" id="phone" style="width:140" /><br /> <label for="sales">Sales/Returns<br />Order No: </label> <input type="text" name="sales" id="sales" style="width:100" /><br /> ……… </fieldset> </form> </body> Next, the labels and input fields of type="text“. Note the onclick event handler called enable() in the name field – more on this later
  • 6. The XHTML Markup #3 <body> <form id="emessage" method="post" action="msgadd.php"> <fieldset style="border:none"> ……. <label for="enq">Nature of<br />Enquiry: </label> <select name="enq" id="enq" style="width:240" /> <option value="0">Please Select</option> <option value="Defective Goods">Defective Goods</option> <option value="Missing Items">Missing Items</option> <option value="Non-Delivery">Non-Delivery</option> </select><span style="color:red"> * </span><br /><br /> ……… </fieldset> </form> </body> Next, the label and drop down selectlistbox
  • 7. The XHTML Markup #4 <body> <form id="emessage" method="post" action="msgadd.php"> <fieldset style="border:none"> ……. <label for="message">Message: </label> <textarea rows="20" cols="60" name="message" id="message"></textarea><span style="color:red"> * </span><br /> <br /> <input type="submit" name="submit" id="submit" value="Send" disabled="disabled" onclick="return checkmessages()" /> <input type="reset" name="reset" id="reset" value="Reset" /> ……… </fieldset> </form> </body> Last, the textareaand submit and reset buttons. Note that the submit button is initially disabled. Note also it’s onclick event handler – we use this to check that the form fields are filled in as required
  • 8. The Required Fields There are four required fields on the form marked with a red asterix (*) When the user clicks the submit button we need to check that they have all been filled in We do this using a javascript function called checkmessages() This is invoked when the user clicks the submit button Our javascript code goes in the <head> section of the document and must be enclosed in <script> .. </script> tags When the user clicks in the name field the submit button will be enabled.
  • 9. The enable() Function function enable() { document.getElementById("emessage").submit.disabled=false; } This is the code that enables the submit button once the user clicks in the name field. Note the use of the document.getElementById() function – this is our way of accessing the form elements.
  • 10. The checkmessages() Function function checkmessages() { vartheMessage = "Invalid Message - Please complete the following: ------------------------------------------------------------------------"; varnoErrors = true; if (document.getElementById("emessage").name.value=="") { theMessage = theMessage + " --> Name"; noErrors = false; } // If no errors, submit the form if (noErrors) { return true; } else { // errors were found, show alert message alert(theMessage); document.getElementById("emessage").submit.disabled=true; return false; } } // end of function checkmessages() This is the code that checks the name field. To check the remaining fields you only need copy and paste this and edit the name of the field being checked. For the select field however you will need to check if the value is "0"
  • 11. Styling the Form To pretty up the form we use a style sheet: <style> label{ float: left; width: 180px; font-weight: bold; } textarea,select,input{ margin-bottom: 5px; } #submit{ margin-left: 200px; margin-top: 5px; width: 100px; } br{ clear: left; } </style>
  • 12. Warning the User If a required field is not filled in we output a warning message to this effect on the screen Let’s assume the name field isn’t filled in.
  • 13. Confirming Form Submission Once the form has been successfully submitted we need to inform the user of this This can be done with a simple php script (see next slide).