HTML DOM Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.

Slides:



Advertisements
Similar presentations
17 HTML, Scripting, and Interactivity Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and.
Advertisements

Chapter 7 JavaScript: Introduction to Scripting. Outline Simple Programs Objects and Variables Obtaining User Input with prompt Dialogs – –Dynamic Welcome.
1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
The Web Warrior Guide to Web Design Technologies
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
Information Technology Center Hany Abdelwahab Computer Specialist.
Computer Science 103 Chapter 4 Advanced JavaScript.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Introduction to scripting
Tables in HTML Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
CST JavaScript Validating Form Data with JavaScript.
4.1 JavaScript Introduction
Deleting and Updating Records in MySQL using PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Page Layout Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
JavaScript Part 1.
History, Navigator, Screen and Form Objects Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
Working with background, images and date object Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
Adding Image, audio and video files to web pages Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and check boxes using HTML Add a pull-down.
Manipulating the DOM CST 200 – JavaScript 3 –
Introduction to HTML 1 Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan.
JavaScript, Fourth Edition
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Introduction to JavaScript Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 1.
Using Client-Side Scripts to Enhance Web Applications 1.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Introduction to Cascading Style-sheets (CSS) Basharat Mahm ood, Department of Computer Science, CIIT,Islamabad, Pakistan 1.
Chapter 5: Windows and Frames
XP Tutorial 6 New Perspectives on JavaScript, Comprehensive1 Working with Windows and Frames Enhancing a Web Site with Interactive Windows.
JavaScript - A Web Script Language Fred Durao
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Review of the DOM Node properties and methods Some ways of accessing nodes Appending, copying and removing nodes Event handling – Inline – Scripting –
1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure.
HTML Overview Part 5 – JavaScript 1. Scripts 2  Scripts are used to add dynamic content to a web page.  Scripts consist of a list of commands that execute.
JavaScript Challenges Answers for challenges
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (NON-Audio version) © Dr. David C. Gibbs WDMD.
HTML FORMS Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan. 1.
CSS properties Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
Javascript Overview. What is Javascript? May be one of the most popular programming languages ever Runs in the browser, not on the server All modern browsers.
HTML 5 Form elements Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Understanding JavaScript and Coding Essentials Lesson 8.
HTML Links and navigation Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Working with the Window Object JavaScript considers the browser window an object, which it calls the window object.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Popup Boxes.
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
Introduction to.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Intro to JavaScript CS 1150 Spring 2017.
Section 17.1 Section 17.2 Add an audio file using HTML
Passing variables between pages
WEB PROGRAMMING JavaScript.
JavaScript: Introduction to Scripting
CS105 Introduction to Computer Concepts JavaScript
Presentation transcript:

HTML DOM Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1

Summary of the previous lecture What is JavaScript? Embedding JavaScript with HTML JavaScript conventions Variables in JavaScript JavaScript operators Input output in JavaScript JavaScript functions Conditional Statements Looping Statements Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 2

Outline Dialog boxes in JavaScript HTML Document Object Model (DOM) Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 3

1. Dialog boxes in JavaScript JavaScript provides the ability to pickup user input or display small amounts of text to the user by using dialog boxes These dialog boxes appear as separate windows and their content depends on the information provided by the user

1.1 Alert Box An alert box is simply a small message box that pops up and gives the user some information An alert dialog box is mostly used to give a warning message to the users When an alert box pops up, the user will have to click "OK" to proceed Syntax: – alert(“message”)

1.1 Alert Box… Start of the function Displays an alert box Calling the function

1.2 Prompt box A prompt box is often used if you want the user to input a value before entering a page When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value If the user clicks "OK" the box returns the input value If the user clicks "Cancel" the box returns null

1.2 Prompt box… Start of the function Prompt box Calling the function

1.3 Confirm box A confirm box is often used if you want the user to verify or accept something When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed If the user clicks "OK", the box returns true If the user clicks "Cancel", the box returns false

1.3 Confirm box User input confirmation Not confirmed

2. Document Object Model (DOM) Once html element are rendered (painted) in the browser window, browser can not recognize them To create interactive web pages it is vital that the browser continues to recognize HTML elements JavaScript enabled browsers do this because they recognize and uses DOM Basharat Mahm ood, Department of Computer Science, CIIT,Islamabad, Pakistan 11

2. Document Object Model (DOM)… The HTML DOM defines a standard set of objects for HTML, and a standard way to access and manipulate HTML documents All HTML elements, along with their containing text and attributes, can be accessed through the DOM – The contents can be modified or deleted, and new elements can be created Basharat Mahm ood, Department of Computer Science, CIIT,Islamabad, Pakistan 12

2. Document Object Model (DOM)… The HTML DOM is platform and language Independent – It can be used by any programming language like Java, JavaScript, and VBScript The HTML DOM can be thought of as a hierarchy moving from the most general object to the most specific Basharat Mahm ood, Department of Computer Science, CIIT,Islamabad, Pakistan 13

2. Document Object Model (DOM)… Basharat Mahm ood, Department of Computer Science, CIIT,Islamabad, Pakistan 14 Window NavigatorDocumentHistoryLocation Forms[ ] Array of forms links[] Array of links Images[] Array of images anchors[] Array of anchors Element[ ] Array of element of forms Textboxes buttons select list Reset files Options[] li

2. Document Object Model (DOM)… document.forms[0].elements[0].value document.images[0].src document.links[0].href

2.1 Retrieving HTML elements The getElementById() method is a workhorse method of the DOM It retrieves a specified element of the HTML document and returns a reference to it To retrieve an element, it must have an unique id – document.getElementById(“element-id”) Basharat Mahm ood, Department of Computer Science, CIIT,Islamabad, Pakistan 16

2.1 Retrieving HTML elements… The returned reference can be used to retrieve element attributes – document.getElementById(“element- id”).attribute – document.getElementById(“pic”).src – document.getElementById(“pic”).height Basharat Mahm ood, Department of Computer Science, CIIT,Islamabad, Pakistan 17

2.1 Retrieving HTML elements… Basharat Mahm ood, Department of Computer Science, CIIT,Islamabad, Pakistan 18 Function starts Getting reference to pic Accessing Attributes Image tag Setting id Calling function

2.2 Retrieving the text of an element innerHTML property defines both the HTML code and the text that occurs between that element's opening and closing – document.getElementById(“element-id”).innerHTML Basharat Mahm ood, Department of Computer Science, CIIT,Islamabad, Pakistan 19

2.2 Retrieving the text of an element Basharat Mahm ood, Department of Computer Science, CIIT,Islamabad, Pakistan 20 Id of paragraphCalling the function Paragraph text Getting reference to element Getting text

2.3 Getting value of attributes getAttribute() method is used to retrieve values of attributes – document.getElementById(“element- id”).getAttribute(“attribute-name”) – document.getElementById(“pic”).getAttribute(“src”) Basharat Mahm ood, Department of Computer Science, CIIT,Islamabad, Pakistan 21

2.3 Getting value of attributes Basharat Mahm ood, Department of Computer Science, CIIT,Islamabad, Pakistan 22 Getting reference to element Using getAttribute function

2.4 Setting value of attributes setAttribute() method is used to set values of attributes – document.getElementById(“element- id”).setAttribute(“attribute-name”, ”Value”) – document.getElementById(“pic”).setAttribute(“src”, ”abc.jpg”) Basharat Mahm ood, Department of Computer Science, CIIT,Islamabad, Pakistan 23

2.4 Setting value of attributes Basharat Mahm ood, Department of Computer Science, CIIT,Islamabad, Pakistan 24 Setting Reference to element Changing the value of attribute

Summary Dialog boxes in JavaScript HTML DOM Retrieving HTML elements Setting HTML elements Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 25

Chapter 11. Beginning HTML, XHTML,CSS, and JavaScript, by Jon Duckett, Wiley Publishing; 2009, ISBN: Chapter 3,6, Learn JavaScript, by Chuck Easttom, Wordware Publishing; 2002, ISBN Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. References