CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr

Slides:



Advertisements
Similar presentations
Chapter 7 JavaScript: Introduction to Scripting. Outline Simple Programs Objects and Variables Obtaining User Input with prompt Dialogs – –Dynamic Welcome.
Advertisements

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.
The Document Object Model (DOM) 1 JavaScript is an object-based language—that is, it’s based on manipulating objects by changing each object’s properties.
JavaScript Objects - DOM CST 200 JavaScript. Objectives Introduce JavaScript objects Introduce Document Object Model Introduce window object Introduce.
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
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
Information Technology Center Hany Abdelwahab Computer Specialist.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
CST JavaScript Validating Form Data with JavaScript.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
HTML DOM.  The HTML DOM defines a standard way for accessing and manipulating HTML documents.  The DOM presents an HTML document as a tree- structure.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
UFCEWT-20-3 Advanced Topics in Web Development Lecture 4 : JavaScript, Browsers & the HTML DOM-API.
Lecture 11 – DOM Scripting SFDV3011 – Advanced Web Development Reference: 1.
Working with Objects Creating a Dynamic Web Page.
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 –
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
JavaScript, Fourth Edition
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Using Client-Side Scripts to Enhance Web Applications 1.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
DHTML: Working with Objects Creating a Dynamic Web Page.
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
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
1 Javascript DOM Peter Atkinson. 2 Objectives Understand the nature and structure of the DOM Add and remove content from the page Access and change element.
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 Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Understanding JavaScript and Coding Essentials Lesson 8.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
HTML DOM Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan 1.
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.
Chapter 10 Dynamic HTML (DHTML) JavaScript, Third Edition.
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.
XML DOM Week 11 Web site:
THE DOM.
Introduction to.
DHTML.
Chapter 5 Validating Form Data with JavaScript
JavaScript and HTML Simple Event Handling 11-May-18.
In this session, you will learn to:
Using DHTML to Enhance Web Pages
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Intro to JavaScript CS 1150 Spring 2017.
JavaScript (JS) Basics
The Document Object Model (DOM) is a W3C standard.
Section 17.1 Section 17.2 Add an audio file using HTML
Web Development & Design Foundations with HTML5 7th Edition
JavaScript and HTML Simple Event Handling 19-Sep-18.
DHTML.
JavaScript Introduction
Week 11 Web site: XML DOM Week 11 Web site:
Web Systems Development (CSC-215)
DHTML Javascript Internet Technology.
DHTML Javascript Internet Technology.
CHAPTER 7 JavaScripts & HTML Documents
CS105 Introduction to Computer Concepts
JavaScript.
Introduction to JavaScript
Web Programming and Design
Creating dynamic/interactive web pages
Web Programming and Design
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr. Tehseen Riaz Abbasi

Web Technologies and Programming Lecture 18

Embedding JavaScript with HTML JavaScript conventions Summary of 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

Today’s Lecture Outline Dialog boxes in JavaScript HTML Document Object Model (DOM)

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

JavaScript has three kind of popup boxes: Alert box Prompt box 1. Dialog boxes in JavaScript JavaScript has three kind of popup boxes: Alert box Prompt box Confirm box

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 Function Displays an Alert Box Calling the Function

1.1 Alert Box… Alert Box

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 Asks user to enter name Writes name on the webpage Calling a function

1.2. Prompt box… Prompt Box Output

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

1.3 Confirm box

The DOM is a W3C (World Wide Web Consortium) standard. 2. Document Object Model (DOM) What is the DOM? The DOM is a W3C (World Wide Web Consortium) standard. The DOM defines a standard for accessing documents: "The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document.”

The W3C DOM standard is separated into 3 different parts: 2. Document Object Model (DOM) The W3C DOM standard is separated into 3 different parts: Core DOM - standard model for all document types XML DOM - standard model for XML documents HTML DOM - standard model for HTML documents

2. HTML 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

2. HTML 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

The HTML DOM is platform and language Independent 2. HTML 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

Textboxes buttons select list 2. Document Object Model (DOM)… Window Navigator Document History Location Forms[ ] Array of forms Images[] Array of images links[] Array of links anchors[] Array of anchors Options[] li Element[ ] Array of element of forms Textboxes buttons select list Reset files

2. Document Object Model (DOM)… When a web page is loaded, the browser creates a Document Object Model of the page. With the object model, JavaScript gets all the power it needs to create dynamic HTML: JavaScript can change all the HTML elements in the page JavaScript can change all the HTML attributes in the page JavaScript can change all the CSS styles in the page JavaScript can remove existing HTML elements and attributes

JavaScript can add new HTML elements and attributes 2. Document Object Model (DOM)… JavaScript can add new HTML elements and attributes JavaScript can react to all existing HTML events in the page JavaScript can create new HTML events in the page

HTML DOM methods are actions you can perform (on HTML Elements). 2. Html Document Object Model (DOM)… HTML DOM methods are actions you can perform (on HTML Elements). HTML DOM properties are values (of HTML Elements) that you can set or change. In the DOM, all HTML elements are defined as objects. The programming interface is the properties and methods of each object. A property is a value that you can get or set (like changing the content of an HTML element). A method is an action you can do (like add or deleting an HTML element).

document.forms[0].elements[0].value document.images[0].src 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”)

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

Getting Reference to “pic” 2.1 Retrieving HTML elements… Function Starts Getting Reference to “pic” Accessing Attributes Setting id Image Tag Calling Function

2.1 Retrieving HTML elements… Image Title Alert Height Alert

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

Getting Element Reference 2.2 Retrieving the text of an element… Getting Element Reference Getting Text Paragraph id Calling Function Paragraph Text

2.2 Retrieving the text of an element Paragraph Text Text Alert

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”)

2.3 Getting value of attributes… Getting Element Reference Using getAttribute() Function

2.3 Getting value of attributes… Image Title Attribute Alert

setAttribute() method is used to set values of attributes 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”)

2.4 Setting value of attributes… Getting Reference Element Changing Attribute Values

Before Setting Attribute Values 2.4 Setting value of attributes… Before Setting Attribute Values After Setting Attribute Values

3.0 HTML DOM Elements Finding HTML Elements To do so, you have to find the elements first. There are a couple of ways to do this: Finding HTML elements by id Finding HTML elements by tag name Finding HTML elements by class name Finding HTML elements by CSS selectors Finding HTML elements by HTML object collections

Finding HTML Element by Id 3.1 HTML DOM Elements Finding HTML Element by Id The easiest way to find an HTML element in the DOM, is by using the element id. This example finds the element with id="intro": Example: var myElement = document.getElementById("intro");

Finding HTML Elements by Tag Name 3.2 HTML DOM Elements Finding HTML Elements by Tag Name This example finds all <p> elements: Example var x = document.getElementsByTagName("p");

Finding HTML Elements by Class Name 3.3 HTML DOM Elements Finding HTML Elements by Class Name If you want to find all HTML elements with the same class name, use getElementsByClassName(). This example returns a list of all elements with class="intro". Example var x = document.getElementsByClassName("intro");

Finding HTML Elements Methods Descriptiondocument.getElementById(id) 3.4 HTML DOM Elements Finding HTML Elements Methods Descriptiondocument.getElementById(id) Find an element by element iddocument.getElementsByTagName(name) Find elements by tag namedocument.getElementsByClassName(name) Find elements by class name

Summary of Today’s Lecture Dialog boxes in JavaScript Alert box Prompt box Confirm box What is DOM? HTML DOM Retrieving HTML elements getElementById() innerHTML getAttribute() setAttribute()

HTML DOM Elements Finding HTML Elements Find an element by element Summary of Today’s Lecture HTML DOM Elements Finding HTML Elements Find an element by element Find elements by tag Find elements by class name

THANK YOU