Java Script 3
Java Script 3
Java Script 3
JavaScript Programming
Presented by
Dr. Geeta Mete
document.getElementById() method
• The document.getElementById() method returns the element of
specified id.
• Dom2.html
document.getElementsByName() method
• getElementsByName() method
• Example of getElementsByName()
• The document.getElementsByName() method
returns all the element of specified name.
• document.getElementsByName("name")
• Here, name is required.
Unit 3 : Document Object Model Presented By : Dr. Geeta Mete
(05) A- JavaScript Programming
Example
• Example of document.getElementsByName()
method
• In this example, we going to count total
number of genders. Here, we are using
getElementsByName() method to get all the
genders.
• Dom3.html
Unit 3 : Document Object Model Presented By : Dr. Geeta Mete
(05) A- JavaScript Programming
document.getElementsByTagName()
method
• getElementsByTagName() method
• Example of getElementsByTagName()
• The document.getElementsByTagName() method
returns all the element of specified tag name.
• document.getElementsByTagName("name")
• Here, name is required.
Example
Example of document.getElementsByTagName()
method
• In this example, we going to count total
number of paragraphs used in the document.
To do this, we have called the
document.getElementsByTagName("p")
method that returns the total paragraphs.
dom4.html
Example
• Another example of
document.getElementsByTagName() method
• In this example, we going to count total
number of h2 and h3 tags used in the
document.
dom5.html
Javascript - innerHTML
• The innerHTML property can be used to write the dynamic
html on the html document.
• It is used mostly in the web pages to generate the dynamic
html such as registration form, comment form, links etc.
• Example of innerHTML property
• In this example, we are going to create the html form when
user clicks on the button.
• In this example, we are dynamically writing the html form
inside the div name having the id mylocation. We are
identifing this position by calling the
document.getElementById() method.
• Dom6.html
Unit 3 : Document Object Model Presented By : Dr. Geeta Mete
(05) A- JavaScript Programming
Example
• Show/Hide Comment Form Example using
innerHTML
• Dom7.html
Javascript - innerText
• Example of innerText property
• The innerText property can be used to write
the dynamic text on the html document. Here,
text will not be interpreted as html text but a
normal text.
Example
• In this example, we are going to display the
password strength when releases the key
after press.
• Dom8.html
Form Validation
• Form validation normally used to occur at the server,
after the client had entered all the necessary data and
then pressed the Submit button. If the data entered by
a client was incorrect or was simply missing, the server
would have to send all the data back to the client and
request that the form be resubmitted with correct
information. This was really a lengthy process which
used to put a lot of burden on the server.
• JavaScript provides a way to validate form's data on the
client's computer before sending it to the web server.
Examples
• FormValidation1.html
End of Unit 3