Client side programming with JavaScript and DHTML Dr Jim Briggs.

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

Chapter 08: Adding Adding Interactivity Interactivity With With Behaviors Behaviors By Bill Bennett Associate Professor MSJC CIS MVC.
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
Essentials for Design JavaScript Level One Michael Brooks
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
Tutorial 6 Creating a Web Form
The Web Warrior Guide to Web Design Technologies
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
JavaScript Forms Form Validation Cookies CGI Programs.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Computer Science 103 Chapter 4 Advanced JavaScript.
Macromedia Dreamweaver 4 Advanced Level Course. Add Rollovers Rollovers or mouseovers are possibly the most popular effects used in designing Web pages.
Lesson 2 Event Handling. Object Event Handlers Most of the objects that make up the Document Object Model respond to asynchronous, user generated events.
JavaScript Client Side scripting. Client-side Scripts Client-side scripts, which run on the user’s workstation can be used to: Validate user inputs entered.
Tutorial 6 Forms Section A - Working with Forms in JavaScript.
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
CST JavaScript Validating Form Data with JavaScript.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
Web Programming Material From Greenlaw/Hepp, In-line/On-line: Fundamentals of the Internet and the World Wide Web 1 Introduction The JavaScript Programming.
CP476 Internet Computing JavaScript and HTML1 1.JavaScript Execution Environment The JavaScript Window object represents the window in which the browser.
JS: DOM Form Form Object Form Object –The Form object represents an HTML form. –For each instance of a tag in an HTML document, a Form object is created.
HTML Forms/Events (Instructor Lesson) The Event model HTML Forms Custom Events 1.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Event and Event Handling.
JavaScript - a Brief Introduction Anupriya. What is JavaScript Object based (not object oriented) programming language –very limited object creation –a.
1 Forms A form is the usual way that information is gotten from a browser to a server –HTML has tags to create a collection of objects that implement this.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
© Cheltenham Computer Training 2001 Macromedia Dreamweaver 4 - Slide No 1 Macromedia Dreamweaver 4 Advanced Level Course.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Dynamic Action with Macromedia Dreamweaver MX Barry Sosinsky Valda Hilley.
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.
10 Adding Interactivity to a Web Site Section 10.1 Define scripting Summarize interactivity design guidelines Identify scripting languages Compare common.
Internet Mark-up Languages CO32036 Part Lecture: Elementary JavaScript.
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.
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.
Lesson13. JavaScript JavaScript is an interpreted language, designed to function within a web browser. It can also be used on the server.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Introduction to JavaScript 41 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 17.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
JavaScript - A Web Script Language Fred Durao
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
44238: Dynamic Web-site Development Client Side Programming Ian Perry Room:C48 Extension:7287
HTML Forms. Slide 2 Forms (Introduction) The purpose of input forms Organizing forms with a and Using different element types to get user input A brief.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 8 Scott Marino.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (NON-Audio version) © Dr. David C. Gibbs WDMD.
COS 125 DAY 20. Agenda Assignment 8 not corrected yet Assignment 9 posted  Due April 16 New course time line Discussion on Scripts 
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
JavaScript II ECT 270 Robin Burke. Outline Functions Events and event handling Form validation.
JavaScript Event Handlers. Introduction An event handler executes a segment of a code based on certain events occurring within the application, such as.
Learning Aim C.  In this section we will look at how text, tables, forms and frames can be used in web pages.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
Tutorial 6 Creating a Web Form
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
Section 10.1 Define scripting
Chapter 5 Validating Form Data with JavaScript
In this session, you will learn to:
JavaScript is a programming language designed for Web pages.
Section 17.1 Section 17.2 Add an audio file using HTML
Web Development & Design Foundations with HTML5 7th Edition
Section 10.1 YOU WILL LEARN TO… Define scripting
JavaScript Basics What is JavaScript?
Presentation transcript:

Client side programming with JavaScript and DHTML Dr Jim Briggs

2 What is JavaScript? Scripting Language Developed by Netscape in 1995 Originally called LiveScript Renamed to form a marketing relationship with Java An open language - no licence required JavaScript is lines of code combined with HTML –JavaScript is supported by all major browsers (but in slightly different ways!) –The client has the option not to run JavaScript

3 What can JavaScript do? JavaScript introduces interactivity to web pages –This is achieved by controlling the browser Common uses for JavaScript: –Validating forms –Performing calculations –Animating images, including rollovers –Creating advertising banners –Detect certain predetermined aspects of the environment e.g. the browser version or required plug-ins –Generate date and time features including calendars and time stamps

4 Tools for the trade Any simple text editor –Textpad –Notepad Specialist HTML editors –Dreamweaver Browsers (for testing and debugging)

5 How to run JavaScript … document.write(“hello World”) …

6 JavaScript the Output

7 JavaScript's Compatibility Some very old browsers don’t support JavaScript –Netscape 1.X and Internet Explorer 3 Some implement it in different ways –Netscape vs. Internet Explorer Getting better!

8 JavaScript's Compatibility To insert HTML that only appears in non- scripting browsers This would also be visible to those that have JavaScript turned off

Animation

10 What is a rollover? As the user moves the mouse over an image or text the view changes It is a reaction to an event It could invoke a status message or change the colour of a graphic on the web page

11 Example 1 Place your mouse here! Example: rollover1.htmlrollover1.html

12 Example 2 code Place your mouse here! rollover2.html

13 Example 3 Use the same method to swap one image for another. rollover3.html

14 Multiple Links It is easy to have multiple rollovers in a page buttonover.html

15 Example 4 - Cycling Banners One feature of JavaScript is its capability to dynamically change images in web pages This technique is usually incorporated into adverts that popup on your web page JavaScript can do this very simply by using an image array The code cycles through a selection of graphics, giving the impression of the graphics rotating This creates dynamically changing content on the page without the need to use frames and layers

16 Cycling Banners Disadvantages: –Only images that exist in the document can change –New one can’t be added –Existing ones can’t be removed Images with differing sizes can still be used Image download times

17 Cycling Banners Image arrays Array contains each of the images required for the page The image then becomes the child object rotbanner.htm

18 Slide Shows Here the user controls the flow of the images This works simply by using the array element numbers Add 1 to move forward Subtract 1 to move backwards Add the navigation to the page slideshow.htm

Form validation

20 Form validation with HTML Forms are used frequently in websites to collect data They incorporate a variety of graphical interface elements, e.g. Radio Buttons, Check Boxes, Pop-up Menus and textual entry fields

21 Form validation with HTML User inputs the data Once completed the Submit button is clicked This triggers an event - sending the data to the web server Here the server-side program interprets the data and acts on it

22 Form validation with HTML Disadvantage: –The user has to complete the whole form and submit it before the data gets validated –The data has to reach the server before the validation can commence The solution: –To validate on the client-side –JavaScript enables validation on the client-side

23 Form Validation using JavaScript Example When changing a password the user is asked to enter the new password twice to check for typos If the text fields do not match an Alert box will appear to inform the user If the password input is accurate then it is sent to the server password_check.html

24 Active site navigation With JavaScript you can create a select and go menu to select options from a drop down list in one click, eliminating the go button Take care not to confuse people who have JavaScript turned off!

25 Active site navigation When the menu is not pulled down, it will display a user prompt This technique is used by many websites to move the user to different sections SelectAndGo.html

26 Validating fields Use Regular Expressions –Powerful way to validate and format text strings –It provides compact way of coding –You need to know the syntax There is only a limited amount of checking that can be done client-side RegExp.html

27 Regular Expressions This regular expression will test the address for us: re = re is the variable the RegExp is assigned to RegExp begins and ends with / ^ indicates beginning of string; $ end \w is any character a-z, A-Z and one or more of the previous item

28 Regular Expression The use of () brackets indicate a group Square brackets [] indicate any one of the characters inside \. means a full stop (. means any character) ? means optional \.\w{2,3} looking for the. followed by either 2 or 3 characters + must exist 1 or more times e.g..com,.ac.uk,.net * after an item indicates 0 or more of the represents character \w+ means 1 or more characters ([\.-]?\w+)* indicates a. or – are allowed in the suffix/prefix of an address

Event handling

30 Event Handling Events are actions that the user performs while visiting your web page These events can be triggered by: –A mouse click –A key press –Form loading

31 The onLoad Event Triggered when the user enters your page and all its elements have loaded –A common use of this event is to have advertisement windows pop up when you first load the page The onLoad command is normally in the tag. If you want to do more than one thing, define a function

32 onUnLoad Event Triggered when the user leaves the site Used commonly again for pop up advertising windows when you leave the site. Can be used to produce an infinite loop of pop up’s - a user’s nightmare! A possible use would be to display an exit message. The onUnLoad is normally on the tag, similar to the onLoad command.

33 Mouse Event Handlers Commands can be associated with most page elements Event only applies to element it is associated with onmousedown onmouseup onclick ondblclick onmouseover onmouseout onmousemove

34 onMousemove Event This is triggered when the user moves the mouse over an element The eyes

35 onMouseover Event This command is used extensively with image rollovers. This event is triggered when the mouse is moved into any area for which the command has been assigned (i.e. over an element)

36 onMouseout Event The reverse of the onMouseover. Triggered when the user moves the mouse out of the area for which the event has been assigned.

37 Form event handling Form handling event are largely used in form validation scripts onSubmit event –Triggered when the user clicks on the Submit button to complete the form –If the result of the handler is false then the form is not sent to the server. onReset Event –Triggered when the user clicks the reset button on the form –A function should be called to (re-)assign the default values to the form.

38 Form Event handling onSelect Event –Is trigger if the user selects text in an INPUT or a TEXTAREA form field onChange Event –Triggered when a user changes a form field. –Used to verify information immediately or to respond to a user’s choice before the submit button is clicked.

Advanced interfaces

40 User Interface Design "MS-Windows" interface elements not available in HTML: –Menu bars –Pull-down menus Need to accomplish with JavaScript

41 Pull down menus Source: pulldownmenu.htmlpulldownmenu.html The function toggleMenu() switches between the menu pulled down and not –currElem is the element to be toggled –nextPos is where you want the top position of the menu to be

42 Sliding menus DHTML enables elements of a page to be switched on or off –Not implemented in Netscape 4 –display attribute: either "none" or "block" Source slidingmenu.htmlslidingmenu.html

43 Tool Tips Tool tips appear when you hold a cursor over an item. Example: tooltips.htmltooltips.html Contains an image map ( … tag) –Associate named map to image ( attribute) –Specify region of an image ( tag) rect, circle or poly –Associate action with that region Can be client-side action (e.g. JavaScript or follow link) or server-side (send co-ordinates to server)

44 Click anywhere form fields In MS-Windows, clicking on the label of a control selects it Browser interaction doesn’t work in the same way - the control requires a precise click Source: clickanywhere.htmlclickanywhere.html