JavaScript Lesson 2 TBE 540 F. Fisher. Prerequisites  Before beginning this lesson, the learner must be able to… Create and edit a web page using a text.

Slides:



Advertisements
Similar presentations
Login The process of identifying oneself on a computer,usually by entering ones username or password.
Advertisements

Internet Services and Web Authoring (CSET 226) Lecture # 5 HyperText Markup Language (HTML) 1.
KompoZer. This is what KompoZer will look like with a blank document open. As you can see, there are a lot of icons for beginning users. But don't be.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
The Web Warrior Guide to Web Design Technologies
FORMs Lesson TBE 540. Prerequisites Before beginning this lesson, the learner must be able to… –Create basic web pages using a text editor and/or a web.
JavaScript 101 Lesson 01: Writing Your First JavaScript.
Information Technology Center Hany Abdelwahab Computer Specialist.
Web Page Development Identify elements of a Web Page Start Notepad
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
CM143 - Web Week 2 Basic HTML. Links and Image Tags.
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.
JavaScript Lesson 1 TBE 540. Prerequisites  Before beginning this lesson, the learner must be able to… Create a basic web page using a text editor and/or.
HTML Lesson 1 TBE 540 Farah Fisher. Prerequisites Before beginning this lesson, the student must be able to… Access web pages and navigate the web Access.
There is a certain way that an HTML file should be set up. The HTML section declares a beginning and an ending. Within the HTML, there should be a HEAD.
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
CIS101 Introduction to Computing Week 12 Spring 2004.
HTMLMR.Mostafa badr1. Lesson 3 HTML Tags Lesson 2 Creating a HTML File Lesson 1: Hyper Text Markup Language (HTML) Basics Get Trained for a Better Future.
HTML Lesson 5 TBE 540. Prerequisites The user must be able to… –Create basic web pages with a text editor and/or a web page editor.
Designing Web Pages Getting to know HTML... What is HTML? Hyper Text Markup Language HTML is the major language of the Internet’s World Wide Web. Web.
Creating a Web Page HTML, FrontPage, Word, Composer.
© 2011 Delmar, Cengage Learning Chapter 2 Developing a Web Page.
Javascript and the Web Whys and Hows of Javascript.
Introduction to HTML. Topics HTML –What is HTML –Parts of an HTML Document –HTML Tags.
Links in HTML. Hyperlinks or links Millions of linked web pages make up the World Wide Web Used to connect a web page to another web page on the same.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
Chapter 2 Developing a Web Page. A web page is composed of two distinct sections: –The head content –The body Creating Head Content and Setting Page Properties.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
JavaScript Part 1.
1 Essential HTML coding By Fadi Safieddine (Week 2)
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
HTML Review HTML and JavaScript. 2 What is HTML? HTML stands for HyperText Markup Language It is the set of instructions hidden behind every web page.
HTML Hyper Text Markup Language. What is an HTML File?  HTML stands for Hyper Text Markup Language  An HTML file is a text file containing small markup.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
Client Side Programming with JavaScript Why use client side programming? Web sides built on CGI programs can rapidly become overly complicated to maintain,
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
LEARNING HTML PowerPoint #1 Cyrus Saadat, Webmaster.
JavaScript - A Web Script Language Fred Durao
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
JavaScript Adding active content to websites. Goals Understand structure of JavaScript Understand rules of coding Add active content to WebPages Add functions.
HTML Form Widgets. Review: HTML Forms HTML forms are used to create web pages that accept user input Forms allow the user to communicate information back.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
XP Tutorial 8 Adding Interactivity with ActionScript.
Introduction to JavaScript Objects, Properties, Methods.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
January 2006Colby College ITS Setting Up Course Pages.
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.
Event Handling. Objectives Using event handlers Simulating events Using event-related methods.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (NON-Audio version) © Dr. David C. Gibbs WDMD.
HTML Basics. HTML Coding HTML Hypertext markup language The code used to create web pages.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
Creating Web Documents: JavaScript Ftp / file management: review Introduction to JavaScript Sources Homework: start review for midterm, work on Project.
Chapter 27 Getting “Web-ified” (Web Applications) Clearly Visual Basic: Programming with Visual Basic nd Edition.
IN THIS LESSON, WE WILL BECOME FAMILIAR WITH HTML AND BEGIN CREATING A WEB PAGE IN YOUR COMPUTER HTML – the foundation.
HTML HTML stands for Hyper Text Markup Language. HTML is used in making the base of a Website You can just use an online website maker like weebly.com.
IN THIS LESSON, WE WILL BECOME FAMILIAR WITH HTML AND BEGIN CREATING A WEB PAGE IN YOUR COMPUTER HTML – the foundation.
Basic HTML Page 1. First Open Windows Notepad to type your HTML code 2.
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
Copyright © Terry Felke-Morris Web Development & Design Foundations with HTML5 8 th Edition CHAPTER 14 KEY CONCEPTS 1 Copyright.
JavaScript Part 1 Introduction to scripting The ‘alert’ function.
Using DHTML to Enhance Web Pages
Midterm Exam Review HTML and JavaScript.
Microsoft® Office FrontPage® 2003 Training
Web Development & Design Foundations with HTML5 7th Edition
Introduction to TouchDevelop
Web Programming and Design
Presentation transcript:

JavaScript Lesson 2 TBE 540 F. Fisher

Prerequisites  Before beginning this lesson, the learner must be able to… Create and edit a web page using a text editor or a web page editor. Edit the HTML code of a web page. Identify JavaScript code within HTML code.

Objectives  After completing this lesson, the learner will be able to… Explain the meaning of “object- oriented” programming. Use a “dot” scheme to identify any part of a web page display. Customize existing JavaScript code.

Object-Oriented Programming  Programming languages come in many varieties.  Older languages like BASIC and FORTRAN accepted input from the user and displayed information.  They could not directly influence “objects” such as graphics or text boxes.

Object-Oriented Programming  JavaScript (and other contemporary languages) are classified as object- oriented, because they can affect objects on the screen.  For example, JavaScript can be used to change an image when the mouse rolls over it.

Addressing Objects  In order to affect objects, JavaScript must have a way of addressing (naming) them.  JavaScript uses a “dot scheme” (parts of the web page are addressed using certain terms with periods/dots in between).

Addressing Objects  For example, a graphic on a web page might be window.document.button or window.document.images[1]  The largest part (window) is first, then a subset of window (document), and finally a subset of document (the image named “button”).

Addressing Objects  If the CSUDH College of Education’s address were done this way, it might look like this: usa.california.carson victor iastreet.1000east.collegeofeduc ation

Addressing Objects  You can see that there are other layers to a web page. From

Properties  Objects on the screen often have properties (attributes) that can be addressed by JavaScript.  For example, each image has a source.  A web page document may have a background color.

Properties  Here are some “dot” addresses: image source (image place named M) window.document.M.src=“me.gif” image source (3rd image on the page – remember that the computer starts counting at 0) window.document.images[2].src= “me.gif” web page background color: window.document.bgcolor.value= “blue”

Example - The Status Bar  At the bottom of most web pages, there is an area called the status bar. It often shows the link addresses.

Example - The Status Bar  JavaScript can be used to put text into the status bar.  For example, in the mouseover.htm example on the class web page, a message was placed in the status bar when the mouse moves over images.

Example - The Status Bar  In the scroller.htm example on the class web page, a message scrolled across the status bar as long as the page was open.  The “dot address” of the status bar is window.status (it doesn’t have anything to do with the web page document, so the term document is not included).

Example - The Status Bar  Here is the code to add to an IMG tag to put text into the status bar: onMouseOver=“window.status=‘HI!’”  Notice that the entire instruction (from window.status to the end is in quotes (“).  The message itself (HI!) is inside single quotes (‘).

Example - The Status Bar  The IMG tag might look like this (name of image file is “hello.jpg”)  Other choices for images are onClick (if you click on the image) and onMouseOut (when you move the mouse away from the image).

Example - Text in a Box  Forms are used to put buttons and input boxes on the web page.  The next JavaScript example will put a message in a text box.  The message will depend on the time of day.  See greet.htm on the class website to try it out.

Example - Text in a Box  This page uses FORM tags for the box (more about FORMs in another PPT): This results in a text box (20 characters long) called greetingbox:

Example - Text in a Box The dot address for the box is: document.greet.greetingbox.value The box is called greetingbox. The box called greetingbox is in the form called greet. The form called greet in in the current web page document. value shows that something will be put into the box.

Example - Text in a Box Here is the JavaScript code (explanations follow): currentTime=new Date(); if (currentTime.getHours() < 12) document.greet.greetingbox.value="Good morning!" else if (currentTime.getHours() < 17) document.greet.greetingbox.value="Good afternoon!" else document.greet.greetingbox.value="Good evening!"

Example - Text in a Box The SCRIPT tags begin and end the JavaScript: currentTime=new Date(); if (currentTime.getHours() < 12) document.greet.greetingbox.value="Good morning!" else if (currentTime.getHours() < 17) document.greet.greetingbox.value="Good afternoon!" else document.greet.greetingbox.value="Good evening!"

Example - Text in a Box new Date() puts the current time/date (from your computer) into the variable currentTime: currentTime=new Date(); if (currentTime.getHours() < 12) document.greet.greetingbox.value="Good morning!" else if (currentTime.getHours() < 17) document.greet.greetingbox.value="Good afternoon!" else document.greet.greetingbox.value="Good evening!"

Example - Text in a Box Look at the structure of the IF statements: if (currentTime.getHours() < 12) document.greet.greetingbox.value="Good morning!" else if (currentTime.getHours() < 17) document.greet.greetingbox.value="Good afternoon!" else document.greet.greetingbox.value="Good evening!” The computer must make a decision about the message, depending on the hour (12=noon, 17=5 pm). currentTime.getHours() contains the hour information (originally from new Date() )

Example - Text in a Box JavaScript IF statements look like this: IF (condition) instructions The condition usually contains == (is equal to) or (greater than). If the condition is true, the instructions are carried out. If the condition is false, the program goes to the next line without performing the instructions.

Example - Text in a Box In this case there are three choices: The hour is < 12 (before noon) - Good morning! The hour is between 12 and 17 (noon and 5 pm) - Good afternoon! The hour is > 17 (after 5 pm) - Good evening! Using IF, ELSEIF and ELSE lets the computer make the choice among these three options.

Example - Text in a Box  If you have looked at the HTML code for greet.htm, you will see something very strange.  The JavaScript is in the BODY section, not the HEAD.

Example - Text in a Box  The reason for this difference is that computer must be instructed to start the JavaScript.  In past examples, we have clicked buttons to start the JavaScript instructions.  This time, the instructions start automatically when the browser reaches that part of the HTML.

More About FORMs?  FORMs will be presented in another PPT presentation.

Self Check - JS Lesson 2  True or false - all programming languages are object-oriented. True False

Self Check - JS Lesson 2  True or false - all programming languages are object-oriented. True False {most current languages are object- oriented, but older languages like BASIC are not}

Self Check - JS Lesson 2  In order to address objects on the screen, object-oriented languages use: Pixel addresses (form top, from left) Dot addresses (e.g., window.status) They cannot address objects.

Self Check - JS Lesson 2  In order to address objects on the screen, object-oriented languages use: Pixel addresses (form top, from left) Dot addresses (e.g., window.status) They cannot address objects.

Self Check - JS Lesson 2  The dot address of the source of an “image place” called M1 would be: window.document.src.M1 window.document.M1.src document.M1.src

Self Check - JS Lesson 2  The dot address of the source of an “image place” called M1 would be: window.document.src.M1 window.document.M1.src document.M1.src window may be deleted when the address refer to the web page document.

Self Check - JS Lesson 2  The dot address of a text box called B in a form called MYFORM would be: window.document.B.MYFORM window.document.MYFORM.B

Self Check - JS Lesson 2  The dot address of a text box called B in a form called MYFORM would be: window.document.B.MYFORM window.document.MYFORM.B

Self Check - JS Lesson 2  The code to put “HI” into a box called B in a form called MYFORM would be: window.document.MYFORM.B=“HI” window.document.MYFORM.B.src=“HI” document.MYFORM.B.value=“HI” window.document.MYFORM.B.value=“HI”

Self Check - JS Lesson 2  The code to put “HI” into a box called B in a form called MYFORM would be: window.document.MYFORM.B=“HI” window.document.MYFORM.B.src=“HI” document.MYFORM.B.value=“HI” window.document.MYFORM.B.value=“HI”