SlideShare a Scribd company logo
Client-side Scripting Languages Introduction to Javascript
Plan of the course Javascript – Why, When, What How to include Javascript in HTML  Javascript syntax Document Object Model Examples
Javascript – Why, When, What At first we had only simple text + links + images pages “ live” pages were required by the market  Netscape invented “LiveScript” in 1995 Later renamed to Javascript Javascript – run on browsers, access dynamically to the html page The language was (is) interpreted usually in different way by the browsers
Include Javascript into HTML Script inclus in pagina html <script type=”text/javascript”> //cod script </script> Script inclus intr-un fisier exterior <script src=”fisier_sursa.js”></script>
When does the code run If the script tag is included in the <head> tag The script is executed when the page is loaded – before actually rendering it If the script is included in the body page The script is executed when the markup is found
Javascript Syntax Very similar with C & Java No types for variables Declare variables using the term var var x=5, y=7; Functions are declared using the function keyword function sum(x,y) { var rez=x+y; return rez;} Calling functions is the same as in C/Java var suma=sum(2,5);
Javascript objects  Objects have  methods (functions) Properties Example var student={nume: &quot;ion&quot;, an:2, note:{mate:9, pc:8}}; alert(student.nume +&quot;<br>&quot; ); alert(student.an +&quot;<br>&quot;); var nota var student={nume: &quot;ion&quot;, an:2, note:{mate:9, pc:8}};
Javascript predefined objects Math http://www.w3schools.com/jsref/jsref_obj_math.asp   String http://www.w3schools.com/jsref/jsref_obj_string.asp   Array http://www.w3schools.com/jsref/jsref_obj_array.asp   Date http://www.w3schools.com/jsref/jsref_obj_date.asp
Examples <script type=&quot;text/javascript&quot;> function printValue() //declare a function { var x=Math.random()*10; //compute the value of x as a random value between 0 and 10 alert(x); //display an alert containing the value of x var y=&quot;a random text&quot;; //create a variable of type string alert(y.length); //display an alert containing the length of y //!!! length is a property and not a method alert(y.substr(0,5)); //compute and display as an alert the substring of y between the first and the 5 th  character alert(x+&quot; &quot;+y.length+“ “+y.substr(5,y.length)); //display as an alert the string formed by x, length of y and the substring formed from the 5 th  character of y until the last one } </script>
Javascript example - followup String concatenation operator “+” The alert is used for displaying information during development. NOT to be used in applications Objects can have methods like y.substr(0,5) and properties like y.length All types of variables are declared using  var
Events HTML elements can detect when the user interacts with them Examples of interactions Mouse over (mouse out) Click Key pressed Blur change We can add javascript code to handle every interaction
Events examples <script type=“text/javascript”> function youClicked(element) {this.innerHTML=&quot;you clicked this element&quot;;} function youMousedOver() {alert(&quot;mouse over detected&quot;); } </script> <h1 onclick=&quot;alert('youclicked');youClicked( this );&quot; onmouseover=&quot;youMousedOver()&quot;> Introduction dans la programmation web</h1>
Javascript Events Why we need and what is the “this” pointer Html element User interacts event1 event2 Event1 associated javascript function In order for this function to be able to modify the element with which the user interacted we need to pass it a reference to the object “this” is the reference to the object on which the event is handled
DOM DOM=Document Object Model DOM = a way to access the elements of a HTML page
DOM The DOM tree contains nodes which can be Html elements Text  The tree elements can be accessed By traversing the tree (See Data structures course) By accessing them directly by name (getElementsByTagName) By accessing them directly by id (getElementById) Addressing them directly (as in an array) The root of the DOM tree is the document
Methods and properties document.write(“text”) Adds the “text” to the given page If the page is finished loading it rewrites it Example <script type=&quot;text/javascript&quot;> function printValue() { var x=Math.random()*10; alert(x); var y=&quot;a random text&quot;; alert(y.length); alert(y.substr(0,5)); alert(x+&quot; &quot;+y.length+&quot;!!!&quot;+y.substr(5,y.length)); document.write(x+&quot; &quot;+y.length+&quot;!!!&quot;+y.substr(5,y.length)); } </script>
DOM Methods and properties getElementsByTagName Returns an array of elements with a given name The we need to know the position of the element we need to modify inside the array function modifySecondH1() { var headersArray=document.getElementsByTagName(&quot;h1&quot;); //retrieves all the elements whose names are h1 //elements’ numbering in the array starts at 0 headersArray[1].innerHTML=Math.random()*5; }
DOM Methods and properties document.getElementById The most used method to access an element of a html page We have to be careful to set ids for the elements function modifyFirstH1() { //retrieve the element with the id h1id1 var h1Element=document.getElementById(&quot;h1id1&quot;); //set the HTML value for the document h1Element.innerHTML=&quot;new title&quot;; }
DOM objects methods and properties Direct access to the element Predefined collections Forms Links  Images document.forms[0].username.value – accesses the first form in the document and sets the value property for the username input
Example – using javascript to validate forms When a form is submitted we need to validate it first on the client-side The form should be validated before submitting The event should be added to the submit button For example we want to check if 2 passwords have the same value and if the username is longer than 4 characters
Validate forms with Javascript – example (I) function validateForm(){ var usernameElement=document.getElementById(&quot;username&quot;); var passwordElement=document.getElementById(&quot;password&quot;); var rePasswordElement=document.getElementById(&quot;repassword&quot;); if(passwordElement.value!=rePasswordElement.value || passwordElement.value.length==0) {alert(&quot;please make sure the password is entered the same twice&quot;);return;} if (usernameElement.value.length<4) {alert(&quot;please make sure the username is longer than 4 letters&quot;);return; } document.forms[0].submit(); }
Example of form validation with Javascript (II) <form action=&quot;script.php&quot; method=&quot;POST&quot;> nom d'utilisateur<input type=&quot;text&quot; id=&quot;username&quot; /><br/> mot de passe<input type=&quot;password&quot; id=&quot;password&quot; /> <br/> mot de passe encore une fois <input id=&quot;repassword&quot; type=&quot;password&quot;> <br/> <input type=&quot;button&quot; value=&quot;send&quot; onclick=&quot;validateForm();&quot;/> </form>
Javascript debugging Firebug – extension for Firefox Allows debugging of scripts Step by step execution Adding breakpoints Watch expressions Visualize the DOM tree
Javascript debugging example

More Related Content

What's hot (20)

PPTX
Introduction to Html5, css, Javascript and Jquery
valuebound
 
PPT
Design Tools Html Xhtml
Ahsan Uddin Shan
 
PPT
HTML
Gouthaman V
 
PPT
AJAX Workshop Notes
Pamela Fox
 
PPT
Xhtml
Abdul Khan
 
PPT
Usability and accessibility on the web
Vlad Posea
 
PPT
Introduction to XML
Jussi Pohjolainen
 
PPT
Introduction to HTML
MayaLisa
 
PPSX
DIWE - Coding HTML for Basic Web Designing
Rasan Samarasinghe
 
ODP
JavaScript and jQuery Fundamentals
BG Java EE Course
 
PPTX
FYBSC IT Web Programming Unit III Document Object
Arti Parab Academics
 
PPT
Uta005 lecture2
vinay arora
 
PPT
Introduction to Cascading Style Sheets
Tushar Joshi
 
PPTX
Unit iv xml
smitha273566
 
PDF
Michael(tm) Smith ED09 presentation
Michael(tm) Smith
 
PPTX
Xhtml
sana mateen
 
PPTX
Html vs xhtml
Yastee Shah
 
PPT
A quick guide to Css and java script
AVINASH KUMAR
 
Introduction to Html5, css, Javascript and Jquery
valuebound
 
Design Tools Html Xhtml
Ahsan Uddin Shan
 
AJAX Workshop Notes
Pamela Fox
 
Xhtml
Abdul Khan
 
Usability and accessibility on the web
Vlad Posea
 
Introduction to XML
Jussi Pohjolainen
 
Introduction to HTML
MayaLisa
 
DIWE - Coding HTML for Basic Web Designing
Rasan Samarasinghe
 
JavaScript and jQuery Fundamentals
BG Java EE Course
 
FYBSC IT Web Programming Unit III Document Object
Arti Parab Academics
 
Uta005 lecture2
vinay arora
 
Introduction to Cascading Style Sheets
Tushar Joshi
 
Unit iv xml
smitha273566
 
Michael(tm) Smith ED09 presentation
Michael(tm) Smith
 
Html vs xhtml
Yastee Shah
 
A quick guide to Css and java script
AVINASH KUMAR
 

Viewers also liked (20)

PPT
C5 Javascript French
Vlad Posea
 
PPT
utilisabilite et accessibilite au web
Vlad Posea
 
PPT
HTML 5 - intro - en francais
Vlad Posea
 
PPT
06 Javascript
Herman Tolle
 
PPTX
Client side scripting and server side scripting
baabtra.com - No. 1 supplier of quality freshers
 
PDF
Client side scripting
Eleonora Ciceri
 
PPTX
IPW 2eme course - HTML
Vlad Posea
 
PPTX
Programarea calculatoarelor c2
Vlad Posea
 
PPTX
Ce mă fac când o să fiu mare - optiuni pentru o cariera in IT
Vlad Posea
 
PPT
C5 Javascript
Vlad Posea
 
PPTX
Linked Open Data in Romania
Vlad Posea
 
PPT
Scripting languages
teach4uin
 
PPT
IPW 3rd Course - CSS
Vlad Posea
 
PPT
Introduction dans la Programmation Web Course 1
Vlad Posea
 
PPT
IPW Course 3 CSS
Vlad Posea
 
PPT
Introduction to Web Programming - first course
Vlad Posea
 
PPTX
Css+html
Vlad Posea
 
PPT
Présentation html5
Kénium
 
PDF
Cours HTML/CSS
Axel Chalon
 
PDF
Beautiful CSS : Structurer, documenter, maintenir
Yves Van Goethem
 
C5 Javascript French
Vlad Posea
 
utilisabilite et accessibilite au web
Vlad Posea
 
HTML 5 - intro - en francais
Vlad Posea
 
06 Javascript
Herman Tolle
 
Client side scripting and server side scripting
baabtra.com - No. 1 supplier of quality freshers
 
Client side scripting
Eleonora Ciceri
 
IPW 2eme course - HTML
Vlad Posea
 
Programarea calculatoarelor c2
Vlad Posea
 
Ce mă fac când o să fiu mare - optiuni pentru o cariera in IT
Vlad Posea
 
C5 Javascript
Vlad Posea
 
Linked Open Data in Romania
Vlad Posea
 
Scripting languages
teach4uin
 
IPW 3rd Course - CSS
Vlad Posea
 
Introduction dans la Programmation Web Course 1
Vlad Posea
 
IPW Course 3 CSS
Vlad Posea
 
Introduction to Web Programming - first course
Vlad Posea
 
Css+html
Vlad Posea
 
Présentation html5
Kénium
 
Cours HTML/CSS
Axel Chalon
 
Beautiful CSS : Structurer, documenter, maintenir
Yves Van Goethem
 
Ad

Similar to C5 Javascript (20)

PPT
JavaScript & Dom Manipulation
Mohammed Arif
 
PPT
Java Script
siddaram
 
PPT
JavaScript
Doncho Minkov
 
PPT
JavaScript Workshop
Pamela Fox
 
PPT
Lecture 5 - Comm Lab: Web @ ITP
yucefmerhi
 
PDF
05 JavaScript #burningkeyboards
Denis Ristic
 
PPS
Advisor Jumpstart: JavaScript
dominion
 
PDF
lect4
tutorialsruby
 
PDF
lect4
tutorialsruby
 
PPT
Javascript: Ajax & DOM Manipulation v1.2
borkweb
 
PDF
Jscript Fundamentals
rspaike
 
PDF
Java script
Ramesh Kumar
 
PPTX
Javascript note for engineering notes.pptx
engineeradda55
 
PPTX
unit4 wp.pptxjvlbpuvghuigv8ytg2ugvugvuygv
utsavsd11
 
PPT
Js ppt
Rakhi Thota
 
PDF
Client sidescripting javascript
Selvin Josy Bai Somu
 
PPTX
Java Script
Kalidass Balasubramaniam
 
PPT
Javascript survival for CSBN Sophomores
Andy de Vera
 
PPTX
BITM3730Week6.pptx
MattMarino13
 
PPTX
Java script
bosybosy
 
JavaScript & Dom Manipulation
Mohammed Arif
 
Java Script
siddaram
 
JavaScript
Doncho Minkov
 
JavaScript Workshop
Pamela Fox
 
Lecture 5 - Comm Lab: Web @ ITP
yucefmerhi
 
05 JavaScript #burningkeyboards
Denis Ristic
 
Advisor Jumpstart: JavaScript
dominion
 
Javascript: Ajax & DOM Manipulation v1.2
borkweb
 
Jscript Fundamentals
rspaike
 
Java script
Ramesh Kumar
 
Javascript note for engineering notes.pptx
engineeradda55
 
unit4 wp.pptxjvlbpuvghuigv8ytg2ugvugvuygv
utsavsd11
 
Js ppt
Rakhi Thota
 
Client sidescripting javascript
Selvin Josy Bai Somu
 
Javascript survival for CSBN Sophomores
Andy de Vera
 
BITM3730Week6.pptx
MattMarino13
 
Java script
bosybosy
 
Ad

More from Vlad Posea (14)

PPTX
Design thinking
Vlad Posea
 
PPTX
Talentul meu – mersul pe bicicletă
Vlad Posea
 
PPTX
Programarea calculatoarelor - Limbajul C
Vlad Posea
 
PPTX
Social semantic web
Vlad Posea
 
PDF
Ghidul Bobocului de la Facultatea de Automatica si Calculatoare vers 2011-2012
Vlad Posea
 
PDF
Json tutorial
Vlad Posea
 
PDF
Javascript ajax tutorial
Vlad Posea
 
PPT
Studiu Referitor La Insertia Pe Piata Muncii (1)
Vlad Posea
 
PPT
Aplicații Web Semantice - Descriere Proiect
Vlad Posea
 
PPT
Stagii In Strainatate
Vlad Posea
 
PPT
Student si/sau Angajat
Vlad Posea
 
PDF
Ghidul bobocului de la Facultatea de Automatica si Calculatoare
Vlad Posea
 
PPT
Tips & Tricks Proiect
Vlad Posea
 
PPT
Boboc Advisory Board Intalnire 1
Vlad Posea
 
Design thinking
Vlad Posea
 
Talentul meu – mersul pe bicicletă
Vlad Posea
 
Programarea calculatoarelor - Limbajul C
Vlad Posea
 
Social semantic web
Vlad Posea
 
Ghidul Bobocului de la Facultatea de Automatica si Calculatoare vers 2011-2012
Vlad Posea
 
Json tutorial
Vlad Posea
 
Javascript ajax tutorial
Vlad Posea
 
Studiu Referitor La Insertia Pe Piata Muncii (1)
Vlad Posea
 
Aplicații Web Semantice - Descriere Proiect
Vlad Posea
 
Stagii In Strainatate
Vlad Posea
 
Student si/sau Angajat
Vlad Posea
 
Ghidul bobocului de la Facultatea de Automatica si Calculatoare
Vlad Posea
 
Tips & Tricks Proiect
Vlad Posea
 
Boboc Advisory Board Intalnire 1
Vlad Posea
 

Recently uploaded (20)

PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PPTX
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Introduction to Indian Writing in English
Trushali Dodiya
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Controller Request and Response in Odoo18
Celine George
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Difference between write and update in odoo 18
Celine George
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 

C5 Javascript

  • 1. Client-side Scripting Languages Introduction to Javascript
  • 2. Plan of the course Javascript – Why, When, What How to include Javascript in HTML Javascript syntax Document Object Model Examples
  • 3. Javascript – Why, When, What At first we had only simple text + links + images pages “ live” pages were required by the market Netscape invented “LiveScript” in 1995 Later renamed to Javascript Javascript – run on browsers, access dynamically to the html page The language was (is) interpreted usually in different way by the browsers
  • 4. Include Javascript into HTML Script inclus in pagina html <script type=”text/javascript”> //cod script </script> Script inclus intr-un fisier exterior <script src=”fisier_sursa.js”></script>
  • 5. When does the code run If the script tag is included in the <head> tag The script is executed when the page is loaded – before actually rendering it If the script is included in the body page The script is executed when the markup is found
  • 6. Javascript Syntax Very similar with C & Java No types for variables Declare variables using the term var var x=5, y=7; Functions are declared using the function keyword function sum(x,y) { var rez=x+y; return rez;} Calling functions is the same as in C/Java var suma=sum(2,5);
  • 7. Javascript objects Objects have methods (functions) Properties Example var student={nume: &quot;ion&quot;, an:2, note:{mate:9, pc:8}}; alert(student.nume +&quot;<br>&quot; ); alert(student.an +&quot;<br>&quot;); var nota var student={nume: &quot;ion&quot;, an:2, note:{mate:9, pc:8}};
  • 8. Javascript predefined objects Math http://www.w3schools.com/jsref/jsref_obj_math.asp String http://www.w3schools.com/jsref/jsref_obj_string.asp Array http://www.w3schools.com/jsref/jsref_obj_array.asp Date http://www.w3schools.com/jsref/jsref_obj_date.asp
  • 9. Examples <script type=&quot;text/javascript&quot;> function printValue() //declare a function { var x=Math.random()*10; //compute the value of x as a random value between 0 and 10 alert(x); //display an alert containing the value of x var y=&quot;a random text&quot;; //create a variable of type string alert(y.length); //display an alert containing the length of y //!!! length is a property and not a method alert(y.substr(0,5)); //compute and display as an alert the substring of y between the first and the 5 th character alert(x+&quot; &quot;+y.length+“ “+y.substr(5,y.length)); //display as an alert the string formed by x, length of y and the substring formed from the 5 th character of y until the last one } </script>
  • 10. Javascript example - followup String concatenation operator “+” The alert is used for displaying information during development. NOT to be used in applications Objects can have methods like y.substr(0,5) and properties like y.length All types of variables are declared using var
  • 11. Events HTML elements can detect when the user interacts with them Examples of interactions Mouse over (mouse out) Click Key pressed Blur change We can add javascript code to handle every interaction
  • 12. Events examples <script type=“text/javascript”> function youClicked(element) {this.innerHTML=&quot;you clicked this element&quot;;} function youMousedOver() {alert(&quot;mouse over detected&quot;); } </script> <h1 onclick=&quot;alert('youclicked');youClicked( this );&quot; onmouseover=&quot;youMousedOver()&quot;> Introduction dans la programmation web</h1>
  • 13. Javascript Events Why we need and what is the “this” pointer Html element User interacts event1 event2 Event1 associated javascript function In order for this function to be able to modify the element with which the user interacted we need to pass it a reference to the object “this” is the reference to the object on which the event is handled
  • 14. DOM DOM=Document Object Model DOM = a way to access the elements of a HTML page
  • 15. DOM The DOM tree contains nodes which can be Html elements Text The tree elements can be accessed By traversing the tree (See Data structures course) By accessing them directly by name (getElementsByTagName) By accessing them directly by id (getElementById) Addressing them directly (as in an array) The root of the DOM tree is the document
  • 16. Methods and properties document.write(“text”) Adds the “text” to the given page If the page is finished loading it rewrites it Example <script type=&quot;text/javascript&quot;> function printValue() { var x=Math.random()*10; alert(x); var y=&quot;a random text&quot;; alert(y.length); alert(y.substr(0,5)); alert(x+&quot; &quot;+y.length+&quot;!!!&quot;+y.substr(5,y.length)); document.write(x+&quot; &quot;+y.length+&quot;!!!&quot;+y.substr(5,y.length)); } </script>
  • 17. DOM Methods and properties getElementsByTagName Returns an array of elements with a given name The we need to know the position of the element we need to modify inside the array function modifySecondH1() { var headersArray=document.getElementsByTagName(&quot;h1&quot;); //retrieves all the elements whose names are h1 //elements’ numbering in the array starts at 0 headersArray[1].innerHTML=Math.random()*5; }
  • 18. DOM Methods and properties document.getElementById The most used method to access an element of a html page We have to be careful to set ids for the elements function modifyFirstH1() { //retrieve the element with the id h1id1 var h1Element=document.getElementById(&quot;h1id1&quot;); //set the HTML value for the document h1Element.innerHTML=&quot;new title&quot;; }
  • 19. DOM objects methods and properties Direct access to the element Predefined collections Forms Links Images document.forms[0].username.value – accesses the first form in the document and sets the value property for the username input
  • 20. Example – using javascript to validate forms When a form is submitted we need to validate it first on the client-side The form should be validated before submitting The event should be added to the submit button For example we want to check if 2 passwords have the same value and if the username is longer than 4 characters
  • 21. Validate forms with Javascript – example (I) function validateForm(){ var usernameElement=document.getElementById(&quot;username&quot;); var passwordElement=document.getElementById(&quot;password&quot;); var rePasswordElement=document.getElementById(&quot;repassword&quot;); if(passwordElement.value!=rePasswordElement.value || passwordElement.value.length==0) {alert(&quot;please make sure the password is entered the same twice&quot;);return;} if (usernameElement.value.length<4) {alert(&quot;please make sure the username is longer than 4 letters&quot;);return; } document.forms[0].submit(); }
  • 22. Example of form validation with Javascript (II) <form action=&quot;script.php&quot; method=&quot;POST&quot;> nom d'utilisateur<input type=&quot;text&quot; id=&quot;username&quot; /><br/> mot de passe<input type=&quot;password&quot; id=&quot;password&quot; /> <br/> mot de passe encore une fois <input id=&quot;repassword&quot; type=&quot;password&quot;> <br/> <input type=&quot;button&quot; value=&quot;send&quot; onclick=&quot;validateForm();&quot;/> </form>
  • 23. Javascript debugging Firebug – extension for Firefox Allows debugging of scripts Step by step execution Adding breakpoints Watch expressions Visualize the DOM tree