Bride of JavaScript Working with JavaScript Objects and Events.

Slides:



Advertisements
Similar presentations
The Web Warrior Guide to Web Design Technologies
Advertisements

JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
JavaScript Forms Form Validation Cookies CGI Programs.
Tutorial 10 Programming with JavaScript
Tutorial 14 Working with Forms and Regular Expressions.
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
Lesson 8 Creating Forms with JavaScript
CST JavaScript Validating Form Data with JavaScript.
Web Programming Material From Greenlaw/Hepp, In-line/On-line: Fundamentals of the Internet and the World Wide Web 1 Introduction The JavaScript Programming.
XP Tutorial 14 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
JavaScript Form Validation
Copyright 2007, Information Builders. Slide 1 Maintain & JavaScript: Two Great Tools that Work Great Together Mark Derwin and Mark Rawls Information Builders.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Chapter 3 Using Validation Controls. What is a Validation Control? A control that validates the value in another control Renders as an HTML tag with an.
Server vs Client-side validation. JavaScript JavaScript is an object-based language. JavaScript is based on manipulating objects by modifying an object’s.
Tutorial 14 Working with Forms and Regular Expressions.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
JavaScript Part 1.
© 2000 – All Rights Reserved - Page 1 Introduction to JavaScript Programming Part Two.
JavaScript Lecture 6 Rachel A Ober
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
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,
Lecture # 6 Forms, Widgets and Event Handling. Today Questions: From notes/reading/life? Share Personal Web Page (if not too personal) 1.Introduce: How.
G053 - Lecture 16 Validating Forms Mr C Johnston ICT Teacher
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.
Using Client-Side Scripts to Enhance Web Applications 1.
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.
1 Forms and Form elements CSD 340 McCoey. 2 Form Object Properties action Usually a call to a server elements encoding method post or get target Methods.
Client-Side Scripting JavaScript.  produced by Netscape for use within HTML Web pages.  built into all the major modern browsers. properties  lightweight,
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
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.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
1 JavaScript Part 3. Functions Allow the user to decide when a particular script should be run by the browser in stead of running as long as the page.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
1 JavaScript in Context. Server-Side Programming.
Making dynamic pages with javascript Lecture 1. Java script java versus javascript Javascript is a scripting language that will allow you to add real.
© 2007 D. J. ForemanJS-1 A Light Introduction for Non-programmers JavaScript for Beginners.
Javascript JavaScript is what is called a client-side scripting language:  a programming language that runs inside an Internet browser (a browser is also.
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.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Tutorial 11 1 JavaScript Operators and Expressions.
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.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
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.
INTERNET APPLICATIONS CPIT405 JavaScript Instructor: Rasha AlOmari
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
Web Development & Design Foundations with HTML5
JavaScript is a programming language designed for Web pages.
Web Programming– UFCFB Lecture 17
Working with Forms and Regular Expressions
New Perspectives on Creating Web Pages with HTML
Tutorial 10: Programming with javascript
JavaScript Basics What is JavaScript?
Presentation transcript:

Bride of JavaScript Working with JavaScript Objects and Events

Form Validation Neonatal Feeding Study

Client vs. Server Side Validation Server-side User submits form to Web server Server validates response and returns to user if correction necessary User resubmits Client-side User submits form and validation is performed on user’s computer After an error correction, form is submitted.

Object-based Language Objects Properties Methods [9.06]

JavaScript Object Hierarchy [9.08]-object hierarchy window.document.REG.MEDRECNO document.REG.MEDRECNO [9.09]-objects in neonatal form

Object Properties [9.10]-partial list of objects and properties object.property = expression EXAMPLE: Changing an Object’s Value EXAMPLE: Displaying Read Only Properties EXAMPLE: Displaying Read Only Properties

Assigning a Property to a Variable var PageColor = document.bgColor; var FrameNumber = window.length; var Browser = navigator.appName;

Properties in Conditional Expressions <!--Hide from older browsers if(document.bgColor=="black") { document.fgColor="white"; } else { document.fgColor="black"; } //Stop hiding-->

Object Methods [ ]-partial list of methods -- also App. D object.method(); history.back(); form.submit(); document.write(“Thank You”); some methods use parameters (like above)

The Revenge of JavaScript Managing Events

Managing Events (session 8.2) [9.15]-list of events Event: a specific action that triggers the browser to run a block of JavaScript commands

Events in Data Entry Look at Figure 9-14 on 9.16

Event Handlers Code added to an HTML tag that is run whenever a particular event occurs.

Event Handlers Syntax HTML_tag = name of tag Properties = properties associated with the tag event_handler = the name of an event handler (9- 15 on 9.17) JavaScript commands = function to be run

Example onClick Event Handler

StartForm() function StartForm() { document.REG.FORMDATE.value= DateToday(); }

function DateToday() function DateToday() { var Today=new Date(); var ThisDay=Today.getDate(); var ThisMonth=Today.getMonth()+1; var ThisYear=Today.getFullYear(); return ThisMonth+"/"+ThisDay+"/"+ThisYear; See 9.20

Emulating Events (Figure 9-22, page 9.22) document.ORDERS.PRODUCT.focus(); document.ORDERS.PRODUCT.blur(); document.ORDERS.submit(); After changes--you might need to save and re-open the file...

Working with a Selection Object The Doctors... [9.24]

Complete Syntax function CheckOther(){ if(document.REG.PHYSICIAN.selectedIndex==7) { document.REG.OTHERNAME.value=prompt("Enter name of physician","Name"); } document.REG.ACT.focus(); }

Prompting for Input prompt("Message", "Default_text"); prompt("Enter your name", "Type name here"); Simple Input

Getting the Physician's Name document.REG.OTHERNAME.value= prompt("Enter the name of physician","Name");

Son of JavaScript Calculations

Calculating APGAR (9.32) TOTAL = ACTIVITY + PULSE + GRIMACE + APPEARANCE + RESPIRATION Almost the same for the other 4... Gets a string and you need to calculate and verify.

Converting Text to a Number The eval function TOTAL = eval("10"); You try: TOTAL = "10" + "5" ; TOTAL = eval("10") + eval("5");

APGAR [9.32] function APGAR() { var A = eval(document.REG.ACT.value); var P = eval(document.REG.PULSE.value); var G = eval(document.REG.GRIMACE.value); var AP = eval(document.REG.APP.value); var R = eval(document.REG.RESP.value); document.REG.TOTAL.value = A + P + G + AP + R; }

Passing User Input to the Array (in the APGAR function) The this keyword: A word reserved by JavaScript to refer to the currently selected object (field) document.REG.PULSE.value=2; would be the same as this.value=2; if the current field is the PULSE field in the form bring passed to the array.

Pass Information about the Currently Selected Field to a Function function SetVal(field) { field.value = 0; }

this is a tracker The object a method is invoked through becomes the value of this.  object.method(); we can now refer to object with this Let's extend this to the APGAR

With APGAR You use this to pass information from the current APGAR field in the form to the APGAR function to make sure the function knows which field is currently selected. In this manner the APGAR function knows if the user enters a 2 for Activity, a 1 for Pulse, etc.

this APGAR Part of the APGAR function (in ): function APGAR(field) { var score = field.value; if(score==0 || score==1 || score==2) { var A = eval(document.REG.ACT.value); In the form:

Using this on APGAR fields <input maxLength="1" name="ACT" onblur="APGAR(this);" size="1" value="0"> <input maxLength="1" name="APP" onblur="APGAR(this);" size="1" value="0"> <input maxLength="1" name="RESP" onblur="APGAR(this);" size="1" value="0">

Validating [9.35] function APGAR(field) { var score = field.value; if(score==0 || score==1 || score==2) { var A = eval(document.REG.ACT.value); var P = eval(document.REG.PULSE.value); var G = eval(document.REG.GRIMACE.value); var AP = eval(document.REG.APP.value); var R = eval(document.REG.RESP.value); document.REG.TOTAL.value = A + P + G + AP + R; } else { alert("You must enter a 0, 1, or 2"); field.focus(); }

Notifying the User [9.37] Alert Box alert("Message"); Confirm confirm("Continue with Program?");

Controlling Form Submission [9.39] function CheckData(){ var parents_agree=document.REG.CONSENT.checked; if(parents_agree) { alert("Form submitted successfully"); return true; } else { alert("You still need parental consent."); return false; } return parents_agree; } The return keyword returns a boolean

Reloading a Page onClick=“location=location.href;”

Complete Syntax function APGAR(field) { var score = field.value; if(score==0 || score==1 || score==2) { var A = eval(document.REG.ACT.value); var P = eval(document.REG.PULSE.value); var G = eval(document.REG.GRIMACE.value); var AP = eval(document.REG.APP.value); var R = eval(document.REG.RESP.value); document.REG.TOTAL.value = A + P + G + AP + R; if(field.name=="RESP") { document.REG.BWGT.focus(); } } else { alert("You must enter a 0, 1, or 2"); field.focus(); }