Dynamic documents with JavaScript

Similar documents
Lecture 5 Dynamic Documents with JavaScript. Dynamic XHTML

Introduction to using HTML to design webpages

Chapter 1 Getting Started with HTML 5 1. Chapter 2 Introduction to New Elements in HTML 5 21

Introduction to WEB PROGRAMMING

Using Dreamweaver CS6

Assignments (4) Assessment as per Schedule (2)

Programmazione Web a.a. 2017/2018 HTML5

Styles, Style Sheets, the Box Model and Liquid Layout

CSS مفاهیم ساختار و اصول استفاده و به کارگیری

CSS: The Basics CISC 282 September 20, 2014

Controlled Assessment Task. Question 1 - Describe how this HTML code produces the form displayed in the browser.

Scientific Communication CITS4008. Designing and Writing Web Pages Rachel Cardell-Oliver 2013 Based on notes by Robyn Owens

AIM. 10 September

HTML & CSS November 19, 2014

Mouse-over Effects. Text based buttons

Overview. Part I: Portraying the Internet as a collection of online information systems HTML/XHTML & CSS

HTML. Mohammed Alhessi M.Sc. Geomatics Engineering. Internet GIS Technologies كلية اآلداب - قسم الجغرافيا نظم المعلومات الجغرافية

Session 4. Style Sheets (CSS) Reading & References. A reference containing tables of CSS properties

PIC 40A. Midterm 1 Review

Introduction to Cascading Style Sheet (CSS)

READSPEAKER ENTERPRISE HIGHLIGHTING 2.5

JavaScript is described in detail in many books on the subject, and there is excellent tutorial material at

Web Development & Design Foundations with HTML5, 8 th Edition Instructor Materials Chapter 14 Test Bank

Html basics Course Outline

TAG STYLE SELECTORS. div Think of this as a box that contains things, such as text or images. It can also just be a

CIE-H12 Web page Sample

ITNP43: HTML Lecture 4

XHTML & CSS CASCADING STYLE SHEETS

Index. alt, 38, 57 class, 86, 88, 101, 107 href, 24, 51, 57 id, 86 88, 98 overview, 37. src, 37, 57. backend, WordPress, 146, 148

CSS stands for Cascading Style Sheets Styles define how to display HTML elements

JavaScript and XHTML. Prof. D. Krupesha, PESIT, Bangalore

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

CITS3403 Agile Web Development 2019 Semester 1

Introducing Cascading Style Sheets. Cascading Style Sheet Basics Creating Styles Using Styles Manipulating Styles Text Formatting with CSS

A Balanced Introduction to Computer Science, 3/E

ADDING FUNCTIONS TO WEBSITE

1/6/ :28 AM Approved New Course (First Version) CS 50A Course Outline as of Fall 2014

HTML & CSS. SWE 432, Fall 2017 Design and Implementation of Software for the Web

JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2) What is JavaScript?

To place an element at a specific position on a page use:

INTERNATIONAL UNIVERSITY OF JAPAN Public Management and Policy Analysis Program Graduate School of International Relations

CS 350 COMPUTER/HUMAN INTERACTION. Lecture 6

Programming the World Wide Web by Robert W. Sebesta

a.) All main headings should be italicized. h1 {font-style: italic;} Use an ordinary selector. HTML will need no alteration.

Programming Lab 1 (JS Hwk 3) Due Thursday, April 28

The Benefits of CSS. Less work: Change look of the whole site with one edit

HTML + CSS. ScottyLabs WDW. Overview HTML Tags CSS Properties Resources

Lesson 5 Introduction to Cascading Style Sheets

COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017)

Introduction to DHTML

COPYRIGHTED MATERIAL. Contents. Chapter 1: Creating Structured Documents 1

HTML and CSS COURSE SYLLABUS

Web Development & Design Foundations with HTML5

Place User-Defined Functions in the HEAD Section

Deccansoft Software Services

12/9/2012. CSS Layout

JS Lab 1: (Due Thurs, April 27)

Using Dreamweaver CS6

CSS.

Cascading Style Sheets (CSS)

CS WEB TECHNOLOGY

Controlling Appearance the Old Way

School of Computer Science and Software Engineering

SEEM4570 System Design and Implementation. Lecture 1 Cordova + HTML + CSS

CSS: formatting webpages

Web Design. Basic Concepts

The Importance of the CSS Box Model

Internet Programming 1 ITG 212 / A

HTML, XHTML, and CSS. Sixth Edition. Chapter 1. Introduction to HTML, XHTML, and

LING 408/508: Computational Techniques for Linguists. Lecture 14

recall: a Web page is a text document that contains additional formatting information in the HyperText Markup Language (HTML)

Unit 20 - Client Side Customisation of Web Pages. Week 2 Lesson 4 The Box Model

CSS Cascading Style Sheets

GIMP WEB 2.0 MENUS. Web 2.0 Menus: Horizontal Navigation Bar with Dynamic Background Image

JavaScript II CSCI 311 SPRING 2017

HTML Summary. All of the following are containers. Structure. Italics Bold. Line Break. Horizontal Rule. Non-break (hard) space.

CSS: Cascading Style Sheets

3.1 Introduction. 3.2 Levels of Style Sheets. - HTML is primarily concerned with content, rather than style. - There are three levels of style sheets

Chapter 8. Programming the Web. For the book Mapping in the Cloud Guilford Press Michael P. Peterson

CISC1600-SummerII2012-Raphael-lec3 1

Problem Description Earned Max 1 HTML/CSS Interpretation 30 2 HTML/CSS Programming 30 3 JavaScript Programming 40 X Extra Credit +1 TOTAL 100

Lecture : 3. Practical : 2. Course Credit. Tutorial : 0. Total : 5. Course Learning Outcomes

Events: another simple example

HTML Markup. Heading Tags

CSCB20 Week 7. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017

Chapter 6. Cascading Style Sheets CSS

Creating BrightPlates Templates

Elementary Computing CSC 100. M. Cheng, Computer Science

First Name Last Name CS-081 March 23, 2010 Midterm Exam

CSC 121 Computers and Scientific Thinking

How to create and edit a CSS rule

introduction to XHTML

Cascading Style Sheets (Part II)

Web Design and Application Development

Table Basics. The structure of an table

- HTML is primarily concerned with content, rather than style. - However, tags have presentation properties, for which browsers have default values

Cascading style sheets, HTML, DOM and Javascript

Cascading Style Sheets for layout II CS7026

Data Visualization (CIS/DSC 468)

Transcription:

Dynamic documents with JavaScript Introduction Informally, a dynamic XHTML document is an XHTML document that, in some way, can be changed while it is being displayed by a browser. Dynamic XHTML is not a new markup language. It is a collection of technologies that allows dynamic changes to documents defined with XHTML. Specifically, a dynamic XHTML document is an XHTML document whose tag attributes, tag contents, or element style properties can be changed by user interaction or the occurrence of a browser event after the document has been, and is still being, displayed. Such changes can be made with an embedded script that accesses the elements of the document as objects in the associated DOM structure. POSITIONING ELEMENTS Cascading Style Sheet Positioning (CSS-P) is completely supported by IE8 and FX3. It provides the means not only to position any element anywhere in the display of a document, but also to move an element to a new position in the display dynamically, using JavaScript to change the positioning style properties of the element. These style properties, which are appropriately named left and top, dictate the distance from the left and top of some reference point to where the element is to appear. Another style property, position, interacts with left and top to provide a higher level of control of placement and movement of elements. The position property has three possible values: absolute, relative, and static. //abspos.html <head> <title>absolute Positioning</title> <style type = "text/css">.regtext { font-family: Cambria; font-size:20pt; width: 1200px;.abstext { position:absolute; top:25px; left:100px; font-family: jokerman; font-size:30pt; width: 500px; color:#0000cd; letter-spacing: 1em;

</style> <p class="regtext">if you need to display dynamic data in your HTML document, it will take a lot of work to edit the HTML each time the data changes.with XML, data can be stored in separate XML files. This way you can focus on using HTML/CSS for display and layout, and be sure that changes in the underlying data will not require any changes to the HTML.With a few lines of JavaScript code, you can read an external XML file and update the data content of your web page.in the real world, computer systems and databases contain data in incompatible formats.xml data is stored in plain text format. This provides a software- and hardware-independent way of storing data.this makes it much easier to create data that can be shared by different applications. </p> <p class="abstext"> X TENSIBLE MARK UP LANGUAGE </p> Output To illustrate the placement of nested elements, the document abspos.html is modified to place the regular text 100 pixels from the top and 100 pixels from the left. The special text is nested inside the regular text by using <div> and <span> tags. The modified document, which is named abspos2.html, is as follows: <title>nested Absolute Positioning</title> <style type = "text/css">.regtext { font-family: Cambria; font-size: 20pt; width: 900px; position:absolute; top: 100px; left: 100px;.abstext { position:absolute; top:25px;

left:100px; font-family: jokerman; font-size:50pt; width: 500px; color:#ddd000; letter-spacing: 1em; </style> <div class="regtext">if you need to display dynamic data in your HTML document, it will take a lot of work to edit the HTML each time the data changes.with XML, data can be stored in separate XML files. This way you can focus on using HTML/CSS for display and layout, and be sure that changes in the underlying data will not require any changes to the HTML.With a few lines of JavaScript code, you can read an external XML file and update the data content of your web page.in the real world, computer systems and databases contain data in incompatible formats.xml data is stored in plain text format. This provides a software- and hardware-independent way of storing data.this makes it much easier to create data that can be shared by different applications. <span class = "abstext"> XTENSIBLE MARKUP LANGUAGE </span> </div> Output

RELATIVE POSITIONING An element that has the position property set to relative, but does not specify top and left property values, is placed in the document as if the position attribute were not set at all. However, such an element can be moved later. If the top and left properties are given values, they displace the element by the specified amount from the position where it would have been placed. In both the case of an absolutely positioned element inside another element and the case of a relatively positioned element, negative values of top and left displace the element upward and to the left, respectively. Relative positioning can be used for a variety of special effects in placing elements. //relpos.html <head><title>relative Positioning</title> <p> I am the <span style = "position: relative; top:10px; font-family: Cambria; font-size:25px; font-style: italic; color: purple;"> CULTURAL SECRETARY </span> of NIT,Raichur </p> Out put

STATIC POSITIONING The default value for the position property is static. A statically positioned element is placed in the document as if it had the position value of relative but no values for top or left were given. The difference is that a statically positioned element cannot have its top or left properties initially set or changed later. Therefore, a statically placed element cannot be displaced from its normal position and cannot be moved from that position later. Moving Elements: Moving an element is simple: Changing the top or left property values causes the element to move on the display. If its position is set to absolute, the element moves to the new values of top and left; if its position is set to relative, it moves from its original position by distances given by the new values of top and left. In the next example, an image is absolutely positioned in the display. The document includes two text boxes, labeled x coordinate and y coordinate, respectively. The user can enter new values for the left and top properties of the image in these boxes. When the button labeled Move It is pressed, the values of the left and top properties of the image are changed to the given values, and the element is moved to its new position. A JavaScript function, stored in a separate file, is used to change the values of left and top in this example. //mover.html <head><title>moving Elements</title> <script type = "text/javascript" src = "Move.js"> </script> <form action=""> x - coordinate: <input type = "text" id = "leftcoord" size = "3" /> <br/> y - coordinate: <input type = "text" id = "topcoord" size = "3" /> <br/> <input type="button" value="move It" onclick = "moveit('nit', document.getelementbyid('topcoord').value, document.getelementbyid ('leftcoord').value)" /> </form> <div id = "nit" style = "position:absolute;top:115px;left:0;"> <img src = "CLASS PHOTO.jpg" alt = "NITR CSE/ISE 2012-2013" /> </div> Move.js function moveit (movee, newtop, newleft) { dom = document.getelementbyid (movee).style; dom.top=newtop + "px"; dom.left=newleft + "px";

Output:

ELEMENT VISIBILITY Document elements can be specified to be visible or hidden with the value of their visibility property. The two possible values for visibility are, quite naturally, visible and hidden. The appearance or disappearance of an element can be controlled by the user through a widget. //showhide.html <head> <title>visibility Control</title> <script type="text/javascript" src="showhide.js"> </script> <form action=""> <div id="nit" style="position:relative; visibility: visible;"> <img src = "images1.jpg" alt = "NIT 2015-2016" /> </div><br> <input type="button" value="toggle nit" onclick = "flipimag()" /> </form> //showhide.js function flipimag() { dom=document.getelementbyid("nit").style; if(dom.visibility == "visible") dom.visibility = "hidden"; else dom.visibility = "visible"; Output

CHANGING COLORS AND FONTS The background and foreground colors of the document display can be dynamically changed, as can the font properties of the text. CHANGING COLORS Dynamic changes to colors are relatively simple. In the next example, the user is presented with two text boxes into which color specifications can be typed one for the document background color and one for the foreground color. The colors can be specified in any of the three ways that color properties can be given in CSS. A JavaScript function that is called whenever one of the text boxes is changed makes the change in the document s appropriate color property: back-groundcolor or color. The first of the two parameters to the function specifies whether the new color is for the background or foreground; the second specifies the new color. The new color is the value property of the text box that was changed by the user. <head> <title>dynamic Colors</title> <script type="text/javascript" src = "dyncolor.js"> </script> <form action=""> Background Color: <input type="text" name="bg" size = "20" onchange="setcolor('bg', this.value);" /> Foreground Color: <input type="text" name="fg" size = "20" onchange="setcolor('fg', this.value);" /> </form>

Initial Output Final Output CHANGING FONTS Web users are accustomed to having links in documents change color when the cursor is placed over them. Use of the mouseover event to trigger a JavaScript event handler allows us to change any property of any element in a document, including text, when the mouse cursor is placed over it. Thus, the font style and font size, as well as the color and background color of text, can be changed when the cursor is placed over the text. The text can be changed back to its original form when an event handler is triggered with the mouseout event. //dynlink.html <head> <title>changing Fonts</title> <style type = "text/css">.regtext { font: cambria; font-size:16pt; </style> <p class="regtext"> The batch of <a style = "color:purple;" onmouseover="this.style.color='red'; this.style.font='italic 20pt Jokerman';" onmouseout ="this.style.color='blue'; this.style.font='bold 17pt Times';" > NIT CSE 2015-2016 </a> always Rocks..!!! </p>

Initial Output Onmouseover output Onmouseout output