SlideShare a Scribd company logo
1 of 28
Download to read offline
Document Object Model (DOM)
Relevance of DOM
• As of now you have learned a new language javascript which can
be embedded in to HTML
• But there is something that really makes JavaScript powerful that
it can access HTML elements and manipulate it
– Ie . You can add/Delete/Modify New HTML elements depending on
user events from browser itself
Relevance of DOM
• But for JavaScript to access any document (HTML/XML), the
document must be conformed to a special logical structure
HTML Document
<html>
<body>
<h1>Hello World</h1>
</body>
</html> JavaScript
DOM structure
HTML
Body Head
h1
XML Document
<name>john</name>
<age>26</age>
<phone>9898</phone
>
4
What is DOM?
• The World Wide Web Consortium (W3C) is the body which sets standards
for the web.
• W3C has defined a standard Document Object Model, known as the W3C
DOM for accessing HTML elements from a browser.
• It views HTML documents as a tree structure of elements and text
embedded within other elements.
• All the browsers are following DOM and because of this the JavaScript code
will work on all the browsers in the same way.
Hierarchy of Objects
Window
document
Location
History
Image
Anchor
Form
Password
Hidden
Submit
Reset
Radio
Checkbox
Button
Select
File Upload
Text
Text area
Option
Hierarchy of Objects
Window
document
Location
History
Image
Anchor
Form
Password
Hidden
Submit
Reset
Radio
Checkbox
Button
Select
File Upload
Text
Text area
Option
Here each node is treated as
objects and it can be accessed
by traversing through the tree
structure
Hierarchy of Objects
Window
document
Location
History
Image
Anchor
Form
Password
Hidden
Submit
Reset
Radio
Checkbox
Button
Select
File Upload
Text
Text area
Option
To access the image
Document.image
Hierarchy of Objects
Window
document
Location
History
Image
Anchor
Form
Password
Hidden
Submit
Reset
Radio
Checkbox
Button
Select
File Upload
Text
Text area
Option
To access the text area
Document.formname.txtarea
name
How to Access username using DOM
<body>
<form name=‚userlogin‛>
Username : <input type=‚text‛ name=‚username‛>
Password : <input type=‚text‛ name=‚pass‛>
</form>
</body>
• document object refers the html document.(<body> tag)
• Inside the document we have a form object
• Inside form we have two textboxes
• According to the DOM we can access the value inside the textbox using
JavaScript like
document. userlogin. username. value
• In a form we are accessing elements by name.
• The name should be unique.
How to Access username using DOM
<head>
<script>
Function getName()
{
name= document.userlogin.value;
alert(name);
}
</script>
</head>
<body>
<form name=‚userlogin‛>
Username : <input type=‚text‛ name=‚username‛>
Password : <input type=‚button‛ onClick=‚getName()‛>
</form>
</body>
Accessing HTML Form Object from JavaScript
Form Object
<form name=‚form1‛>
<input type=‚radio‛ name=‚rad1‛ value=‚1‛>Yes<br>
<input type=‚radio‛ name=‚rad1‛ value=‚0‛>No<br>
</form>
• Each form in a document creates
a form object.
• A document can have more than
one form
• Form objects in a document are
stored in a forms[ ] collection.
• The elements on a form are
stored in an elements[ ] array.
Form Object
<form name=‚form1‛>
<input type=‚radio‛ name=‚rad1‛ value=‚1‛>Yes<br>
<input type=‚radio‛ name=‚rad1‛ value=‚0‛>No<br>
</form>
• The elements on a form are
stored in an elements[ ] array.
Form Object
<form name=‚form1‛>
<input type=‚radio‛ name=‚rad1‛ value=‚1‛>Yes<br>
<input type=‚radio‛ name=‚rad1‛ value=‚0‛>No<br>
</form>
document.forms[0].elements[0].value
Form object - detailed
action : Reflects the ACTION attribute.
elements : An array reflecting all the elements in a form.
length : Reflects the number of elements on a form.
method : Reflects the METHOD attribute.
target : Reflects the TARGET attribute.
reset() : Resets a form.
submit() : Submits a form.
Methods
Properties
Event Handlers
onReset(), onSubmit()
Text, Textarea, Password, hidden Objects
• Properties
– defaultValue : Reflects the VALUE attribute.
– name : NAME attribute.
– type : Reflects the TYPE attribute.
– value : Reflects the current value of the Text object’s field.
• Methods
– focus() : Gives focus to the object.
– blur() : Removes focus from the object.
– select() : Selects the input area of the object.
• Event Handler
– onBlur : when a form element loses focus
– onChange : field loses focus and its value has been modified.
– onFocus : when a form element receives input focus.
– onSelect : when a user selects some of the text within a text field.
Radio object
• Properties
– name, type, value, defaultChecked, defaultvalue, checked
– checked property will have a Boolean value specifying the selection state of a radio
button. (true/false)
• Methods
– click( ), focus( ), blur( )
• Event Handler
– onClick, onBlur, onFocus()
if(document.forms[0].rad1[0].checked == true)
{
alert(‘button is checked’);
}
Checkbox object
• Properties
– checked, defaultChecked, name, type, value
• Methods
– click()
• Event Handler
– onClick, onBlur, onFocus()
if(document.form1.chk1.checked==true)
red=255;
else
red=0;
Button, reset, submit Objects
• Properties
– form, name, type, value
• Methods
– click( ), blur( ), focus( )
• Event Handler
– onClick, onBlur, onFocus, onMouseDown, onMouseUp
Disabled property
• The disabled property (Applicable for all the form controls)
– If this attribute is set to true, the button is disabled
– This attribute can use with all other form elements to disable the element
<input type=‚button‛ name=‚b1‛ value=‚ok‛ disabled>
document.forms[0].b1.disabled=true;
– To enable a control, you must set the disabled property value as false.
Using submit() method
• Submit button can invoke the action page without using any client side
scripting.
• If you want to submit a form other than using the submit button, you need
to invoke the submit() method of the form.
• Eg:
function submitForm()
{
document.form1.action=‚http://xyz.com‛;
document.form1.submit();
}
<input type=‚button‛ onlick=‚submitForm()‛>
/* this is mainly required in the server side programming */
Select Object
• The user can choose one or more items from a selection list, depending on
how the list was created.
• Methods
– blur(), focus()
• Event Handler
– onBlur, onChange, onFocus
Option Object
• An option in a selection list.
index The zero-based index of an element in the Select.options array.
selected Specifies the current selection state of the option
text Specifies the text for the option
value Specifies the value for the option
length The number of elements in the Select.options array.
Properties
Try out - Form Validation
• Create a form with the following fields:
– Name
– Age
– Email
• What to validate
– All the fields are entered.
– Name should be a string with minimum 3 Character.
– Age should be a number between 1 and 100
– Email should be a string with an ‚@‛ character.
• Make use of String functions and top level functions to validate the fields
JavaScript Programming Tips
• Use alert() method for Debugging
1. Use JavaScript alert statement to display variable values
2. Use alert() to find out on which line error is occurring.Processing of the
JavaScript is halted until the OK button is clicked.
• More Tips
– Put your common JavaScript validation functions into a common file (.js).
– validate data on all the fields in your forms ( if storing inside database)
– JavaScript string object has a lot of functionality that many people spend
time programming themselves
– Limit the number of characters in a field and disable the fields which user
need not enter the data. (use MAXLENGTH of form elements)
Questions?
‚A good question deserve a good grade…‛
End of Day
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

More Related Content

What's hot (20)

Web engineering - HTML Form
Web engineering -  HTML FormWeb engineering -  HTML Form
Web engineering - HTML Form
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
 
html forms
html formshtml forms
html forms
 
05 html-forms
05 html-forms05 html-forms
05 html-forms
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
 
HTML5 - Forms
HTML5 - FormsHTML5 - Forms
HTML5 - Forms
 
Html tables, forms and audio video
Html tables, forms and audio videoHtml tables, forms and audio video
Html tables, forms and audio video
 
Html forms
Html formsHtml forms
Html forms
 
20 html-forms
20 html-forms20 html-forms
20 html-forms
 
Building html forms
Building html formsBuilding html forms
Building html forms
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
Html form tag
Html form tagHtml form tag
Html form tag
 
2. HTML forms
2. HTML forms2. HTML forms
2. HTML forms
 
HTML Forms Tutorial
HTML Forms TutorialHTML Forms Tutorial
HTML Forms Tutorial
 
Functional GUIs with F#
Functional GUIs with F#Functional GUIs with F#
Functional GUIs with F#
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validation
 
Html Form Controls
Html Form ControlsHtml Form Controls
Html Form Controls
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
 
Complete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScriptComplete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScript
 

Viewers also liked

Hyperlocalisation or "localising everything"
Hyperlocalisation or "localising everything"Hyperlocalisation or "localising everything"
Hyperlocalisation or "localising everything"Daniel_Rhodes
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsNicole Ryan
 
Lessons from a Dying CMS
Lessons from a Dying CMSLessons from a Dying CMS
Lessons from a Dying CMSSandy Smith
 
Don't Fear the Regex - CapitalCamp/GovDays 2014
Don't Fear the Regex - CapitalCamp/GovDays 2014Don't Fear the Regex - CapitalCamp/GovDays 2014
Don't Fear the Regex - CapitalCamp/GovDays 2014Sandy Smith
 
Don't Fear the Regex LSP15
Don't Fear the Regex LSP15Don't Fear the Regex LSP15
Don't Fear the Regex LSP15Sandy Smith
 
GAIQ - Regular expressions-google-analytics
GAIQ - Regular expressions-google-analyticsGAIQ - Regular expressions-google-analytics
GAIQ - Regular expressions-google-analyticsAnkita Kishore
 
TDA Center Depok update 2014 (Concept)
TDA Center Depok update 2014 (Concept)TDA Center Depok update 2014 (Concept)
TDA Center Depok update 2014 (Concept)Herri Setiawan
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsJames Gray
 
Unicode Regular Expressions
Unicode Regular ExpressionsUnicode Regular Expressions
Unicode Regular ExpressionsNova Patch
 
Multibyte string handling in PHP
Multibyte string handling in PHPMultibyte string handling in PHP
Multibyte string handling in PHPDaniel_Rhodes
 
Architecting with Queues for Scale, Speed, and Separation (DCPHP 3/11/15)
Architecting with Queues for Scale, Speed, and Separation (DCPHP 3/11/15)Architecting with Queues for Scale, Speed, and Separation (DCPHP 3/11/15)
Architecting with Queues for Scale, Speed, and Separation (DCPHP 3/11/15)Sandy Smith
 
Iterators, ArrayAccess & Countable (Oh My!) - Madison PHP 2014
Iterators, ArrayAccess & Countable (Oh My!) - Madison PHP 2014Iterators, ArrayAccess & Countable (Oh My!) - Madison PHP 2014
Iterators, ArrayAccess & Countable (Oh My!) - Madison PHP 2014Sandy Smith
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsdavidfstr
 
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?daoswald
 
Working with Databases and MySQL
Working with Databases and MySQLWorking with Databases and MySQL
Working with Databases and MySQLNicole Ryan
 
Architecting with Queues - Northeast PHP 2015
Architecting with Queues - Northeast PHP 2015Architecting with Queues - Northeast PHP 2015
Architecting with Queues - Northeast PHP 2015Sandy Smith
 
How to report a bug
How to report a bugHow to report a bug
How to report a bugSandy Smith
 
EDUPUB 2013: Schema.org LRMI and A11Y for Discovery
EDUPUB 2013: Schema.org LRMI and A11Y for DiscoveryEDUPUB 2013: Schema.org LRMI and A11Y for Discovery
EDUPUB 2013: Schema.org LRMI and A11Y for DiscoveryGerardo Capiel
 

Viewers also liked (20)

Hyperlocalisation or "localising everything"
Hyperlocalisation or "localising everything"Hyperlocalisation or "localising everything"
Hyperlocalisation or "localising everything"
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Lessons from a Dying CMS
Lessons from a Dying CMSLessons from a Dying CMS
Lessons from a Dying CMS
 
Grokking regex
Grokking regexGrokking regex
Grokking regex
 
Don't Fear the Regex - CapitalCamp/GovDays 2014
Don't Fear the Regex - CapitalCamp/GovDays 2014Don't Fear the Regex - CapitalCamp/GovDays 2014
Don't Fear the Regex - CapitalCamp/GovDays 2014
 
Don't Fear the Regex LSP15
Don't Fear the Regex LSP15Don't Fear the Regex LSP15
Don't Fear the Regex LSP15
 
Intoduction to php strings
Intoduction to php  stringsIntoduction to php  strings
Intoduction to php strings
 
GAIQ - Regular expressions-google-analytics
GAIQ - Regular expressions-google-analyticsGAIQ - Regular expressions-google-analytics
GAIQ - Regular expressions-google-analytics
 
TDA Center Depok update 2014 (Concept)
TDA Center Depok update 2014 (Concept)TDA Center Depok update 2014 (Concept)
TDA Center Depok update 2014 (Concept)
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Unicode Regular Expressions
Unicode Regular ExpressionsUnicode Regular Expressions
Unicode Regular Expressions
 
Multibyte string handling in PHP
Multibyte string handling in PHPMultibyte string handling in PHP
Multibyte string handling in PHP
 
Architecting with Queues for Scale, Speed, and Separation (DCPHP 3/11/15)
Architecting with Queues for Scale, Speed, and Separation (DCPHP 3/11/15)Architecting with Queues for Scale, Speed, and Separation (DCPHP 3/11/15)
Architecting with Queues for Scale, Speed, and Separation (DCPHP 3/11/15)
 
Iterators, ArrayAccess & Countable (Oh My!) - Madison PHP 2014
Iterators, ArrayAccess & Countable (Oh My!) - Madison PHP 2014Iterators, ArrayAccess & Countable (Oh My!) - Madison PHP 2014
Iterators, ArrayAccess & Countable (Oh My!) - Madison PHP 2014
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
Regular Expressions: Backtracking, and The Little Engine that Could(n't)?
 
Working with Databases and MySQL
Working with Databases and MySQLWorking with Databases and MySQL
Working with Databases and MySQL
 
Architecting with Queues - Northeast PHP 2015
Architecting with Queues - Northeast PHP 2015Architecting with Queues - Northeast PHP 2015
Architecting with Queues - Northeast PHP 2015
 
How to report a bug
How to report a bugHow to report a bug
How to report a bug
 
EDUPUB 2013: Schema.org LRMI and A11Y for Discovery
EDUPUB 2013: Schema.org LRMI and A11Y for DiscoveryEDUPUB 2013: Schema.org LRMI and A11Y for Discovery
EDUPUB 2013: Schema.org LRMI and A11Y for Discovery
 

Similar to Dom

WEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptxWEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptxkarthiksmart21
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object ModelWebStackAcademy
 
Client-side JavaScript
Client-side JavaScriptClient-side JavaScript
Client-side JavaScriptLilia Sfaxi
 
Dom date and objects and event handling
Dom date and objects and event handlingDom date and objects and event handling
Dom date and objects and event handlingsmitha273566
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoFu Cheng
 
Javascript part 2 DOM.pptx
Javascript part 2 DOM.pptxJavascript part 2 DOM.pptx
Javascript part 2 DOM.pptxdeepa339830
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy stepsprince Loffar
 
Web technologies-course 09.pptx
Web technologies-course 09.pptxWeb technologies-course 09.pptx
Web technologies-course 09.pptxStefan Oprea
 
Web forms and html (lect 4)
Web forms and html (lect 4)Web forms and html (lect 4)
Web forms and html (lect 4)Salman Memon
 
Easy javascript
Easy javascriptEasy javascript
Easy javascriptBui Kiet
 

Similar to Dom (20)

Javascript dom
Javascript domJavascript dom
Javascript dom
 
WEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptxWEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptx
 
Cmsc 100 (web forms)
Cmsc 100 (web forms)Cmsc 100 (web forms)
Cmsc 100 (web forms)
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Client-side JavaScript
Client-side JavaScriptClient-side JavaScript
Client-side JavaScript
 
ppt- u 2.pptx
ppt- u 2.pptxppt- u 2.pptx
ppt- u 2.pptx
 
Dom date and objects and event handling
Dom date and objects and event handlingDom date and objects and event handling
Dom date and objects and event handling
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
 
Part 7
Part 7Part 7
Part 7
 
Jquery fundamentals
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
 
Javascript part 2 DOM.pptx
Javascript part 2 DOM.pptxJavascript part 2 DOM.pptx
Javascript part 2 DOM.pptx
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
 
Web technologies-course 09.pptx
Web technologies-course 09.pptxWeb technologies-course 09.pptx
Web technologies-course 09.pptx
 
Class 21
Class 21Class 21
Class 21
 
Class 21
Class 21Class 21
Class 21
 
Web forms and html (lect 4)
Web forms and html (lect 4)Web forms and html (lect 4)
Web forms and html (lect 4)
 
Forms Part 1
Forms Part 1Forms Part 1
Forms Part 1
 
U2A3
U2A3U2A3
U2A3
 
Easy javascript
Easy javascriptEasy javascript
Easy javascript
 
Javascript
JavascriptJavascript
Javascript
 

More from baabtra.com - No. 1 supplier of quality freshers

More from baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Recently uploaded

UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 

Recently uploaded (20)

UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 

Dom

  • 2. Relevance of DOM • As of now you have learned a new language javascript which can be embedded in to HTML • But there is something that really makes JavaScript powerful that it can access HTML elements and manipulate it – Ie . You can add/Delete/Modify New HTML elements depending on user events from browser itself
  • 3. Relevance of DOM • But for JavaScript to access any document (HTML/XML), the document must be conformed to a special logical structure HTML Document <html> <body> <h1>Hello World</h1> </body> </html> JavaScript DOM structure HTML Body Head h1 XML Document <name>john</name> <age>26</age> <phone>9898</phone >
  • 4. 4 What is DOM? • The World Wide Web Consortium (W3C) is the body which sets standards for the web. • W3C has defined a standard Document Object Model, known as the W3C DOM for accessing HTML elements from a browser. • It views HTML documents as a tree structure of elements and text embedded within other elements. • All the browsers are following DOM and because of this the JavaScript code will work on all the browsers in the same way.
  • 6. Hierarchy of Objects Window document Location History Image Anchor Form Password Hidden Submit Reset Radio Checkbox Button Select File Upload Text Text area Option Here each node is treated as objects and it can be accessed by traversing through the tree structure
  • 9. How to Access username using DOM <body> <form name=‚userlogin‛> Username : <input type=‚text‛ name=‚username‛> Password : <input type=‚text‛ name=‚pass‛> </form> </body> • document object refers the html document.(<body> tag) • Inside the document we have a form object • Inside form we have two textboxes • According to the DOM we can access the value inside the textbox using JavaScript like document. userlogin. username. value • In a form we are accessing elements by name. • The name should be unique.
  • 10. How to Access username using DOM <head> <script> Function getName() { name= document.userlogin.value; alert(name); } </script> </head> <body> <form name=‚userlogin‛> Username : <input type=‚text‛ name=‚username‛> Password : <input type=‚button‛ onClick=‚getName()‛> </form> </body>
  • 11. Accessing HTML Form Object from JavaScript
  • 12. Form Object <form name=‚form1‛> <input type=‚radio‛ name=‚rad1‛ value=‚1‛>Yes<br> <input type=‚radio‛ name=‚rad1‛ value=‚0‛>No<br> </form> • Each form in a document creates a form object. • A document can have more than one form • Form objects in a document are stored in a forms[ ] collection. • The elements on a form are stored in an elements[ ] array.
  • 13. Form Object <form name=‚form1‛> <input type=‚radio‛ name=‚rad1‛ value=‚1‛>Yes<br> <input type=‚radio‛ name=‚rad1‛ value=‚0‛>No<br> </form> • The elements on a form are stored in an elements[ ] array.
  • 14. Form Object <form name=‚form1‛> <input type=‚radio‛ name=‚rad1‛ value=‚1‛>Yes<br> <input type=‚radio‛ name=‚rad1‛ value=‚0‛>No<br> </form> document.forms[0].elements[0].value
  • 15. Form object - detailed action : Reflects the ACTION attribute. elements : An array reflecting all the elements in a form. length : Reflects the number of elements on a form. method : Reflects the METHOD attribute. target : Reflects the TARGET attribute. reset() : Resets a form. submit() : Submits a form. Methods Properties Event Handlers onReset(), onSubmit()
  • 16. Text, Textarea, Password, hidden Objects • Properties – defaultValue : Reflects the VALUE attribute. – name : NAME attribute. – type : Reflects the TYPE attribute. – value : Reflects the current value of the Text object’s field. • Methods – focus() : Gives focus to the object. – blur() : Removes focus from the object. – select() : Selects the input area of the object. • Event Handler – onBlur : when a form element loses focus – onChange : field loses focus and its value has been modified. – onFocus : when a form element receives input focus. – onSelect : when a user selects some of the text within a text field.
  • 17. Radio object • Properties – name, type, value, defaultChecked, defaultvalue, checked – checked property will have a Boolean value specifying the selection state of a radio button. (true/false) • Methods – click( ), focus( ), blur( ) • Event Handler – onClick, onBlur, onFocus() if(document.forms[0].rad1[0].checked == true) { alert(‘button is checked’); }
  • 18. Checkbox object • Properties – checked, defaultChecked, name, type, value • Methods – click() • Event Handler – onClick, onBlur, onFocus() if(document.form1.chk1.checked==true) red=255; else red=0;
  • 19. Button, reset, submit Objects • Properties – form, name, type, value • Methods – click( ), blur( ), focus( ) • Event Handler – onClick, onBlur, onFocus, onMouseDown, onMouseUp
  • 20. Disabled property • The disabled property (Applicable for all the form controls) – If this attribute is set to true, the button is disabled – This attribute can use with all other form elements to disable the element <input type=‚button‛ name=‚b1‛ value=‚ok‛ disabled> document.forms[0].b1.disabled=true; – To enable a control, you must set the disabled property value as false.
  • 21. Using submit() method • Submit button can invoke the action page without using any client side scripting. • If you want to submit a form other than using the submit button, you need to invoke the submit() method of the form. • Eg: function submitForm() { document.form1.action=‚http://xyz.com‛; document.form1.submit(); } <input type=‚button‛ onlick=‚submitForm()‛> /* this is mainly required in the server side programming */
  • 22. Select Object • The user can choose one or more items from a selection list, depending on how the list was created. • Methods – blur(), focus() • Event Handler – onBlur, onChange, onFocus
  • 23. Option Object • An option in a selection list. index The zero-based index of an element in the Select.options array. selected Specifies the current selection state of the option text Specifies the text for the option value Specifies the value for the option length The number of elements in the Select.options array. Properties
  • 24. Try out - Form Validation • Create a form with the following fields: – Name – Age – Email • What to validate – All the fields are entered. – Name should be a string with minimum 3 Character. – Age should be a number between 1 and 100 – Email should be a string with an ‚@‛ character. • Make use of String functions and top level functions to validate the fields
  • 25. JavaScript Programming Tips • Use alert() method for Debugging 1. Use JavaScript alert statement to display variable values 2. Use alert() to find out on which line error is occurring.Processing of the JavaScript is halted until the OK button is clicked. • More Tips – Put your common JavaScript validation functions into a common file (.js). – validate data on all the fields in your forms ( if storing inside database) – JavaScript string object has a lot of functionality that many people spend time programming themselves – Limit the number of characters in a field and disable the fields which user need not enter the data. (use MAXLENGTH of form elements)
  • 26. Questions? ‚A good question deserve a good grade…‛
  • 28. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com