Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.

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

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
HTML 5 and CSS 3, Illustrated Complete Unit L: Programming Web Pages with JavaScript.
Lesson 12- Unit L Programming Web Pages with JavaScript.
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.
Tutorial 10 Programming with JavaScript
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
JavaScript Demo Presented by … Jaisingh Sumit jain Sudhindra Taran Deep arora.
Web Programming Material From Greenlaw/Hepp, In-line/On-line: Fundamentals of the Internet and the World Wide Web 1 Introduction The JavaScript Programming.
Server vs Client-side validation. JavaScript JavaScript is an object-based language. JavaScript is based on manipulating objects by modifying an object’s.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Programming with JavaScript (Chapter 10). XP Various things Midterm grades: Friday Winter Career Fair – Thursday, April 28, 2011 (11 am to 3 pm). – MAC.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
JavaScript II ECT 270 Robin Burke. Outline JavaScript review Processing Syntax Events and event handling Form validation.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
JavaScript 1. What is JavaScript? JavaScript allows web authors to create dynamic pages that react to user interaction. It is an Object-based because.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
DHTML: Dynamic HTML Internet Technology1. What is DHTML? A collection of enhancements to HTML ► To create dynamic and interactive websites Combination.
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.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
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.
What is Java Script? An extension to HTML. An extension to HTML. Allows authors to incorporate some functionality in their web pages. (without using CGI.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
1 JavaScript in Context. Server-Side Programming.
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Tutorial 10 Programming with JavaScript
Done by: Hanadi Muhsen1 Tutorial 1.  Learn the history of JavaScript  Create a script element  Write text to a Web page with JavaScript  Understand.
Using Client-Side Scripts to Enhance Web Applications 1.
JavaScript - A Web Script Language Fred Durao
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
Overview of Form and Javascript fundamentals. Brief matching exercise 1. This is the software that allows a user to access and view HTML documents 2.
Web Development 101 Presented by John Valance
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
1 JavaScript in Context. Server-Side Programming.
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.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
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.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
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.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
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.
Introduction to.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Tutorial 10 Programming with JavaScript
Web Development & Design Foundations with HTML5
JavaScript Event Handling.
Web Development & Design Foundations with HTML5 7th Edition
14 A Brief Look at JavaScript and jQuery.
DHTML Javascript Internet Technology.
DHTML Javascript Internet Technology.
Tutorial 10 Programming with JavaScript
Presentation transcript:

Extending HTML CPSC 120 Principles of Computer Science April 9, 2012

HTML Pages are Static Text!  An HTML page contains markup tags that control the display of the page data.  HTML links allow user navigation but do not change the page content, display style, etc.  Various methods were proposed for allowing active “scripts” to be included in HTML pages.  Most common methods are including CSS and Javascript. HTML 5 will have more features!  You can also dynamically generate page content using server-side scripting. See our textbook.

Overview of Javascript  Javascript is a programming language, loosely based on Sun Microsystems Java, describing commands added to an HTML page as a “script”.  A script is executed by the web browser. It is a client-side program, running locally on your computer.  Javascript is interpreted by your web browser, first reading, decoding, then carrying out the script actions.  Javascript “knows” about Web page structure via the Document Object Model or DOM. This includes forms, backgrounds, buttons, links, inputs, etc.  Javascript includes common program structures such as variables, assignments, loops, conditionals, etc. Same idea as PBASIC but without mechanicals.

Javascript Design Features  JS is client-side so security is a fundamental concern. Most JS scripts cannot directly access local disk files, send , etc.  JS scripts are active ONLY on the page where they are located. You cannot “refer” across pages to variables.  JS connects to the DOM so you can access and set values for page content, input fields, colors, etc.  JS can display alert dialogs, open child windows, and react to specific key and mouse actions.  JS can modify page characteristics dynamically, changing the display while the user is viewing it.  Common JS actions are button rollovers, image manipulation and movement, input form validation, slide shows, and navigation.

DOM Hierarchy

DOM Objects For HTML Pages  Document: entire HTML page contents  Document objects such as anchors, forms, buttons, tables, etc located inside the document. These have names and ids used by JS to refer to them for access, making changes, etc.  For any given object, it has attributes which the HTML codes like We can use Javascript to access and change those attributes when we invoke the script. We can use Javascript to access and change those attributes when we invoke the script.

Forms and Form Elements Forms are DOM objects that include input boxes, buttons, etc that allow user input on HTML pages with some automated actions: Check User Data Check User Data </form>

Javascript Access to DOM We use a dot notation to access items in the DOM using Javascript. Dots indicate we are moving lower in the hierarchy, ending with attributes and values at the lowest level. Examples: document.body.bgColor refers to the current background color of my page. We can change this by a JS assignment statement: document.body.bgColor = ‘#ff0000’; document.body.bgColor = ‘#ff0000’; Or use the built-in DOM method setAttribute: document.body.setAttribute(‘bgColor’, ‘#ff0000’); document.body.setAttribute(‘bgColor’, ‘#ff0000’); To immediately access a lower level document element, say an img: we can assign it an id then use code like this: document.getElementById(‘myImage’).src=‘lolcat.jpg’; we can assign it an id then use code like this: document.getElementById(‘myImage’).src=‘lolcat.jpg’;

Notice Javascript Uses Functions  JS built-in commands often take the form of mathematical functions: f(x) or f(x,y).  So, to invoke an alert dialog box we use: alert(‘Alert message goes here’); alert(‘Alert message goes here’);  The string supplied to the function is called a parameter. Parameters can be strings, numbers, or even DOM objects.  Functions can also return values so we often return a true or false value in our code: function doAlert() { alert(‘Caution: input field empty!’); return false; } function doAlert() { alert(‘Caution: input field empty!’); return false; }

Built-in Javascript  Remember, JS is interpreted by the browser so it needs to be fed our commands in some way.  We code our JS actions as functions and then invoke them (much like subroutines in PBASIC) when desired.  A common method is to invoke a JS functions when some user action is done on our page such as clicking a button, loading the page itself, etc. Example: Say something! Say something! Here we are enhancing an HTML button object which has text Say something! When the button is clicked, the browser invokes the onClick handler which calls the built-in JS alert function. This displays a dialog box. The words in the box are the string parameter to alert().

Javascript using section  We often need to perform more elaborate operations in a page so we collect some JS functions which can be called when needed.  The functions are inside a script tag like so: … our custom JS functions go here … … our custom JS functions go here …  We try to create functions that accept appropriate parameters and return useful values.  Example: // A comment. Function to test if parameter is empty string or not. // A comment. Function to test if parameter is empty string or not. function checkEmptyString (myString) { if ( myString.length == 0 ) return true; else return false; // Respond } // End of function </script>

Working with Javascript  The syntax is more complex than seems necessary. Fussy issues of ==, semi-colon, etc.  Errors in JS can be hard to debug. Typically something just does not work as desired. Where is the trouble? We have a JS console in Firefox and Firebug is a more complex debugger tool.  Users worried about security can turn off JS in their browser so your scripts will not work.  Different browsers may interpret JS in slightly different ways.  CSS can often provide a better solution to style changes, rollovers, etc.