Mark Dixon Page 1 03 – Dynamic HTML (client-side scripting)

Slides:



Advertisements
Similar presentations
Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
Advertisements

The Web Warrior Guide to Web Design Technologies
Mark Dixon Page 1 05 – Conditional Execution. Mark Dixon Page 2 Admin: Test (next week) In class test –teaching week 6 50 minutes short answer (5 - 6.
Mark Dixon, SoCCE SOFT 131Page 1 20 – Web applications: HTML and Client-side code.
JavaScript- Introduction. What it is and what it does? What it is? It is NOT Java It is NOT Server-side programming Users can see code It is a client-side.
Mark Dixon Page 1 02 – Dynamic HTML (client-side scripting)
Mark Dixon, SoCCE SOFT 131Page 1 16 – Web applications: HTML and Client-side code.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Conditional Execution.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Mark Dixon Page 1 Tech – HTML. Mark Dixon Page 2 Admin Attendance Register: –log in to your profile.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Server vs Client-side validation. JavaScript JavaScript is an object-based language. JavaScript is based on manipulating objects by modifying an object’s.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
M Dixon 1 Web-Application Development Workshop. M Dixon 2 Session Aims & Objectives Aims –to introduce the main concepts involved in creating web-applications.
Event-driven Programming
02 – Client-side code: JavaScript
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
M Dixon 1 Soft – Module Introduction and HTML.
JavaScript is a client-side scripting language. Programs run in the web browser on the client's computer. (PHP, in contrast, is a server-side scripting.
1 Essential HTML coding By Fadi Safieddine (Week 2)
Mark Dixon Page 1 3 – Web applications: Server-side code (JSP)
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.
M Dixon 1 04 – Data Types & Debugging. Questions: Expressions a)What is the result of: 7 + Int(8.245) b)Write an expression to: put a random number into.
Mark Dixon 1 05 – Conditional Execution. Mark Dixon 2 Admin: Test (next week) In class test –teaching week 6 50 minutes short answer (5 - 6 words) currently.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
Mark Dixon, SoCCE SOFT 131Page 1 02 – Dynamic HTML (client-side scripting)
Mark Dixon Page 1 18 – Web applications: Server-side code (PhP)
Mark Dixon Page 1 06 – Conditional Execution. Mark Dixon Page 2 Admin: Test (next week) In class test –teaching week 6 50 minutes short answer (5 - 6.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Variables. Mark Dixon, SoCCE SOFT 131Page 2 Admin: Test (next week) In class test –teaching week 6 –university week.
Mark Dixon Page 1 Soft – Module Introduction and HTML.
Mark Dixon Page 1 Web-Application Development Workshop.
Mark Dixon Page 1 03 – Dynamic HTML (client-side scripting)
M Dixon 1 03 – Dynamic HTML (client-side scripting)
Mark Dixon Page 1 04 – Information Processing: Expressions, Operators & Functions.
M Dixon 1 Web-Application Development Workshop. M Dixon 2 Session Aims & Objectives Aims –to introduce the main concepts involved in creating web-applications.
JavaScript Syntax, how to use it in a HTML document
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.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Expressions, Operators & Functions.
Mark Dixon, SoCCE SOFT 131Page 1 02 – Dynamic HTML (client-side scripting)
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 8 Scott Marino.
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
JavaScript Making Web pages come alive. Objectives Be able to read JavaScript scripts Be able to write JavaScript scripts.
M Dixon 1 Tech HTML. M Dixon 2 Admin Attendance Register: –log in to your profile.
Mark Dixon Page 1 Soft – HTML. Mark Dixon Page 2 Admin Attendance Register: –log in to your profile.
Mark Dixon Page 1 Tech – HTML. Mark Dixon Page 2 Admin Attendance Register: –log in to your profile.
Mark Dixon Page 1 04 – Information Processing: Expressions, Operators & Functions.
Mark Dixon Page 1 04 – Information Processing: Expressions, Operators & Functions.
HTML JAVASCRIPT. CONTENTS Javascript Example NOSCRIPT Tag Advantages Summary Exercise.
Mark Dixon Page 1 08 – Variables. Mark Dixon Page 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40)
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Mark Dixon 1 06 – Conditional Execution. Mark Dixon 2 Admin: Test (next week) In class test –teaching week 7 50 minutes short answer (5 - 6 words max)
M Dixon 1 02 – Dynamic HTML (client-side scripting)
Mark Dixon Page 1 04 – Conditional Execution. Mark Dixon Page 2 Questions: Expressions a)What is the result of: 10 * Int( ) b)How many functions.
Chapter 27 Getting “Web-ified” (Web Applications) Clearly Visual Basic: Programming with Visual Basic nd Edition.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
1 JavaScript and Dynamic Web Pages Lecture 7. 2 Static vs. Dynamic Pages  A Web page uses HTML tags to identify page content and formatting information.
Mark Dixon, SoCCE SOFT 131Page 1 03 – Conditional Execution.
04 – Information Processing: Expressions, Operators & Functions
Section 17.1 Section 17.2 Add an audio file using HTML
Web Development & Design Foundations with HTML5 7th Edition
WEB PROGRAMMING JavaScript.
Tutorial 10: Programming with javascript
Introduction to Programming and JavaScript
Programming with Microsoft Visual Basic 2008 Fourth Edition
Presentation transcript:

Mark Dixon Page 1 03 – Dynamic HTML (client-side scripting)

Mark Dixon Page 2 Questions: HTML Consider the following HTML: Next Page a)Give an example of a tag b)Give an example of an element c)Give an example of an attribute Next Page href=“next.htm”

Mark Dixon Page 3 Questions: HTML a)Is the following a tag? Hello b)Is the following an element? c)Is the following an attribute? d)How many tags are there in: Title e)How many attributes are there in: No (element) No (start tag) 4 2

Mark Dixon Page 4 Admin: On-line Quiz Useful, but limited –multiple choice, same concepts –actual tests are free text

Mark Dixon Page 5 Session Aims & Objectives Aims –introduce you to the fundamental aspects of dynamic (interactive) web pages via client-side scripting Objectives, after this week’s sessions, you should be able to: –Add objects to a web-page –Create Event Handler Procedures to do things in response to an event of a object –Put Assignment instructions in the event handler, that change the value of properties at run-time

Mark Dixon Page 6 Dynamic processing (what) HTML is static –identical on each load –very limiting Dynamic processing –client-side: browser (this week) quicker (no request-response cycle) insecure (view source) limited (can't access server-side databases) –server-side: server application (next term) slower more powerful

Mark Dixon Page 7 Example: Colour Change Trigger (when)Actions (what) Click event of Red button Change background to Red MouseOver event of Red button Make button text capitals (RED) MouseOut event of Red button Make button text normal (Red) Click event of Blue button Change background to Blue MouseOver event of Blue button Make button text capitals (BLUE) MouseOut event of Blue button Make button text normal (Blue) Events: –Click: user releases left mouse button on object –MouseOver: mouse moves over object –MouseOut: mouse mouse moves off object

Mark Dixon Page 8 Active Content Allow active content:

Mark Dixon Page 9 Tags Colour Change <input id="btnRed" type="button" value="Red" onclick="btnRed_OnClick()" onmouseover="btnRed_OnMouseOver()" onmouseout="btnRed_OnMouseOut()" /> function btnRed_OnClick(){ document.bgColor = "red"; } function btnRed_OnMouseOver(){ btnRed.value = "RED"; } function btnRed_OnMouseOut(){ btnRed.value = "Red"; } Use tags to create buttons

Mark Dixon Page 10 Tag Colour Change <input id="btnRed" type="button" value="Red" onclick="btnRed_OnClick()" onmouseover="btnRed_OnMouseOver()" onmouseout="btnRed_OnMouseOut()" /> function btnRed_OnClick(){ document.bgColor = "red"; } function btnRed_OnMouseOver(){ btnRed.value = "RED"; } function btnRed_OnMouseOut(){ btnRed.value = "Red"; } Java Script Use tags to enclose script code

Mark Dixon Page 11 Event Handler Procedures Colour Change <input id="btnRed" type="button" value="Red" onclick="btnRed_OnClick()" onmouseover="btnRed_OnMouseOver()" onmouseout="btnRed_OnMouseOut()" /> function btnRed_OnClick(){ document.bgColor = "red"; } function btnRed_OnMouseOver(){ btnRed.value = "RED"; } function btnRed_OnMouseOut(){ btnRed.value = "Red"; } Event Handler Procedure

Mark Dixon Page 12 Objects & Events Colour Change <input id="btnRed" type="button" value="Red" onclick="btnRed_OnClick()" onmouseover="btnRed_OnMouseOver()" onmouseout="btnRed_OnMouseOut()" /> function btnRed_OnClick (){ document.bgColor = "red"; } function btnRed_OnMouseOver (){ btnRed.value = "RED"; } function btnRed_OnMouseOut (){ btnRed.value = "Red"; } Object Event

Mark Dixon Page 13 Instructions Colour Change <input id="btnRed" type="button" value="Red" onclick="btnRed_OnClick()" onmouseover="btnRed_OnMouseOver()" onmouseout="btnRed_OnMouseOut()" /> function btnRed_OnClick(){ document.bgColor = "red"; } function btnRed_OnMouseOver(){ btnRed.value = "RED"; } function btnRed_OnMouseOut(){ btnRed.value = "Red"; } Assignment: Object.Property = Literal btnRed.Value = "Red"

Mark Dixon Page 14 Sequence Inside event procedures –lines executed in sequence

Mark Dixon Page 15 Assignment Statements Order is important: btnRed.Value = "Red"; The above means: put "Red" into the Value of btnRed destination (must be object property) data flow source (object property or literal)

Mark Dixon Page 16 Errors: Assignment btnRed.Value = "Red"; "Red" = btnRed.Value; btnRed.Value = document.bgColor; 67 = document.bgColor; put "Red" into the Value of btnRed put the Value of btnRed into "Red" put the bgColor of the document into the Value of btnRed put the bgColor of the document into 67  

Mark Dixon Page 17 Errors: function { Every function must have } Colour Change <input id="btnRed" type="button" value="Red" onclick="btnRed_OnClick()" onmouseover="btnRed_OnMouseOver()" onmouseout="btnRed_OnMouseOut()" /> function btnRed_OnClick(){ document.bgColor = "red"; } function btnRed_OnMouseOver(){ btnRed.value = "RED"; function btnRed_OnMouseOut(){ btnRed.value = "Red"; } missing }

Mark Dixon Page 18 Example: Puppy Freya's web page Welcome, Freya's web page. Freya likes her toy. <input id="btnPuppy" type="button" value="Large" onclick="btnPuppy_OnClick()" /> function btnPuppy_OnClick(){ document.title = "Freya (large image)"; picFace.src = "FaceLarge.jpg"; }

Mark Dixon Page 19 Errors: Duplicate function Can't have 2 functions with same name Don't need to: put both lines in same function Freya's web page Welcome, Freya's web page. Freya likes her toy. <input id="btnPuppy" type="button" value="Large" onclick="btnPuppy_OnClick()" /> function btnPuppy_OnClick(){ document.title = "Freya (large image)"; } function btnPuppy_OnClick(){ picFace.src = "FaceLarge.jpg"; } 

Mark Dixon Page 20 Example: Puppy (code) Freya's web page Welcome, Freya's web page. Freya likes her toy. <input id="btnPuppy" type="button" value="Large" onclick="btnPuppy_OnClick()" /> function btnPuppy_OnClick(){ document.title = "Freya (large image)" picFace.src = "FaceLarge.jpg" } Script ignored, until button pressed picture and button, given identifiers (names)

Mark Dixon Page 21 Question: Parts of Code In the following code, name: a)a property b)a keyword c)an object d)an event e)an event handler function btnPuppy_OnClick(){ document.title = "Puppy (large image)"; picFace.src = "FaceLarge.jpg"; } title src function document picFace click btnPuppy_OnClick

Mark Dixon Page 22 Question: Assignment Which of the following are valid: document.bgColor = ; document.bgColor = "red"; "red" = document.bgColor; document = "red"; btnRed = "Hello";    

Mark Dixon Page 23 Example: Ball Character (design) Trigger (when)Actions (what) click event of Right buttonmove ball character right click event of Left buttonmove ball character left click event of Up buttonmove ball character up click event of Down buttonmove ball character down

Mark Dixon Page 24 Absolute Positioning change properties – change position picBall.style.posTop picBall.style.posLeftpicBall.width picBall.height document.body.clientWidth

Mark Dixon Page 25 Example: Ball Character (script) Ball Character <input type="button" id="btnRight" value="Right" onclick="btnRight_OnClick()" /> <input type="button" id="btnDown" value="Down" onclick="btnDown_OnClick()" /> function Window_OnLoad (){ picBall.style.poslLeft = 200; picBall.style.posTop = 100; } function btnRight_OnClick (){ picBall.style.posLeft = picBall.style.posLeft + 10; } function btnDown_OnClick (){ picBall.style.posTop = picBall.style.posTop + 10; }

Mark Dixon Page 26 Substitution Right hand side of assignment (after = sign) –contains expressions (calculations)

Mark Dixon Page 27 Example: Sound Sound <object id="sndPlayer" classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" style="width:0px; height:0px;"> function btnFart_onClick(){ sndPlayer.URL = "Fart.wav" }

Mark Dixon Page 28 Tutorial Exercise: Setup LEARNING OBJECTIVE: to change your computer's settings so that Visual Studio works properly TASK 1: Enable active content in Internet Explorer: 1.1 Start Internet Explorer 1.2 Click the Tools Menu 1.3 Click the Internet Options Item 1.4 Click the Advanced tab 1.5 Ensure 'Disable Script Debugging' is unchecked 1.6 Ensure 'Allow active content on My Computer' is checked 1.7 Click the OK button 1.8 Close Internet Explorer

Mark Dixon Page 29 Tutorial Exercise: Colour Change LEARNING OBJECTIVE: to understand objects, events, properties, and event handler procedures, so that you can create dynamic content in your web-pages TASK 1: Get the Red button from the Colour Change example working. (the code is provided) TASK 2: Get the Blue button working. (You will need to work out what code to use. Use the code provided as inspiration) TASK 3: Add another button (you choose the colour).

Mark Dixon Page 30 Tutorial Exercise: Puppy LEARNING OBJECTIVE: to understand objects, events, properties, and event handler procedures, so that you can create dynamic content in your web-pages TASK 1: Get the Puppy example working. (code provided, images in resources area on server). TASK 2: Add a button, which changes the image back to the smaller picture.

Mark Dixon Page 31 Tutorial Exercise: Ball Char LEARNING OBJECTIVE: to understand objects, events, properties, and event handler procedures, so that you can create dynamic content in your web-pages TASK 1: Get the Right and Down buttons from the Ball Character example working. (code provided, images in resources area on server). TASK 2: Get the Left and Up buttons working. (You will need to work out what code to use. Use the code provided as inspiration) TASK 3: Make the Ball Character blink when the user moves the mouse over it. (You will need to add code that changes the picture) TASK 4: Add a button to move the Ball Character diagonally. (You will need two lines of code in the same event handler)