Client-Side Web Application Development with JavaScript ISYS 350.

Slides:



Advertisements
Similar presentations
Chapter 7 JavaScript: Introduction to Scripting. Outline Simple Programs Objects and Variables Obtaining User Input with prompt Dialogs – –Dynamic Welcome.
Advertisements

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?
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
The Web Warrior Guide to Web Design Technologies
Client-Side Web Application Development with Java ISYS 350.
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.
Forms Review. 2 Using Forms tag  Contains the form elements on a web page  Container tag tag  Configures a variety of form elements including text.
Web Basics ISYS546. Basic Tools Web server –Default directory, default home page –Virtual directory Web page editor –Front Page Web page languages –HTML,
Javascript Document Object Model. How to use JavaScript  JavaScript can be embedded into your html pages in a couple of ways  in elements in both and.
Web Basics ISYS546. Basic Tools Web Server –Default directory, default home page –Virtual directory Web Page Editor –Front Page Web Languages –HTML, XML.
Client Side Scripting BICS546. Client-Side vs Server-Side Scripting Client-side scripting: –The browser requests a page. –The server sends the page to.
Creating Web Pages with HTML and CSS ISY 475. HTML Introduction History: – Standard.
Web Page Introduction. What is a web page? A web page is a text file containing markup language tags. –A markup language combines text and extra information.
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.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
JAVASCRIPT HOW TO PROGRAM -2 DR. JOHN P. ABRAHAM UTPA.
CO1552 Web Application Development HTML Forms. Websites can be made more interactive by providing facilities for users to provide data To get user entered.
JavaScript and The Document Object Model MMIS 656 Web Design Technologies Acknowledgements: 1.Notes from David Shrader, NSU GSCIS 2.Some material adapted.
JavaScript - Document Object Model. Bhawna Mallick 2 Unit Plan What is DOM and its use? Hierarchy of DOM objects. Reflection of these objects in an HTML.
Introduction to JavaScript Dr. John P. Abraham University of Texas – Pan American.
Client-Side Web Application Development with JavaScript ISYS 350.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Client-Side Web Application Development with JavaScript
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Execution Environment for JavaScript " Java Script Window object represents the window in which the browser displays documents. " The Window object provides.
JavaScript Part 1.
1 CLIENT-SIDE SCRIPTS. Objectives 2 Learn how to reference objects in HTML documents using the HTML DOM and dot syntax Learn how to create client-side.
1 JavaScript. 2 What’s wrong with JavaScript? A very powerful language, yet –Often hated –Browser inconsistencies –Misunderstood –Developers find it painful.
Server-Side Scripting with Java Server Page, JSP ISYS 350.
Web Page Introduction. What is a web page? A web page is a text file containing markup language tags. –A markup language combines text and extra information.
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.
Server-Side Scripting with Java Server Page, JSP ISYS 350.
Chapter 8 Cookies And Security JavaScript, Third Edition.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Using Client-Side Scripts to Enhance Web Applications 1.
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.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
Website Development with PHP and MySQL Saving Data.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
Chapter 5: Windows and Frames
Lecture 10 JavaScript: DOM and Dynamic HTML Boriana Koleva Room: C54
Client-Side Web Application Development with JavaScript ISYS 350.
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.
XP Tutorial 8 Adding Interactivity with ActionScript.
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
Introduction to JavaScript Objects, Properties, Methods.
JavaScript, Fourth Edition
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Server-Side Scripting with Java Server Page, JSP ISYS 350.
XP Review 1 New Perspectives on JavaScript, Comprehensive1 Introducing HTML and XHTML Creating Web Pages with HTML.
Server-Side Scripting with Java Server Page, JSP ISYS 350.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
INTERNET APPLICATIONS CPIT405 Forms, Internal links, meta tags, search engine friendly websites.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
XHTML Forms.
Chapter 5 Validating Form Data with JavaScript
In this session, you will learn to:
Section 17.1 Section 17.2 Add an audio file using HTML
14 A Brief Look at JavaScript and jQuery.
Client-Side Web Application Development with JavaScript
Client-Side Web Application Development with JavaScript
Introduction to JavaScript
Presentation transcript:

Client-Side Web Application Development with JavaScript ISYS 350

Types of Web pages Static page: – The contents of a web page is predefined by HTML tags and other mark up languages. Example: david chao’s home page. Dynamic page – A web page includes contents produced by a programming language when the page is opened. – Examples: Pages that display current date/time, visitor counter – Yahoo home page Pages that display results based on a database query. – Yahoo’s Finance/Enter symbol/Historical prices

Technologies for Creating Dynamic Pages Client-side technology – HTML and Browser Document Object Model (DOM) – JavaScript Server-side technology – Microsoft.Net – PHP – Java – Others

Example of Client-side Page using HTML, DOM and JavaScript

HTML Introduction History: – Standard – The World Wide Web Consortium (W3C) HTML 4 HTML 5: – Multimedia controls Video, audio, canvas – Web storage: With HTML5, web pages can store data locally within the user's browser.

Online Resources for Learning HTML w3schools.com –

HTML Tags (Elements) Heading section –,,,, etc. Body section –,, to,, – Formatting:,,, – Comment: – List – Image – Table:, : a new row in table, : a new cell in a table row. – Form:,,

HTML Attributes HTML elements can have attributes that provide additional information about an element. Attributes are always specified in the start tag Attributes come in name/value pairs like: name="value“ Name and value are case-sensitive and lowercase is recommended. Examples: – Id: Specifies a unique id for an element – title: Specifies extra information about an element (displayed as a tool tip)

TABLE Tag Year Value at BeginYr Dep During Yr Total to EndOfYr

FORM Tag Form attributes: – action: Specify the URL of a program on a server or an address to which a form’s data will be submitted. – method: Get: the form’s data is appended to the URL specified by the Action attribute as a QueryString. Post: A preferred method for database processing. Form’s data is sent in the HTTP body. – mame: Form’s name

QueryString A QueryString is a set of name=value pairs appended to a target URL. It can be used to pass information from one webpage to another. To create a QueryString: – Add a question mark (?) immediately after a URL. – Followed by name=value pairs separated by ampersands (&). Example:

Adding HTML Controls Tools/Palette/HTML, JSPCode Clips

Creating HTML Form

Create a Form Using NetBean

Step by Step 1. Add a form tag: – Name property – Action: server-side program; leave it blank for client-side 2. Add lables by typing 3. Add text input 4. Add dropdown list: – Number of options 5. Add radiobutton – All buttons belong to a group 6. Add button – Lable – Type: Submit – submit to a server Standard – client-side 7. Add to start a new line

Dropdown List Example 4% 4.5% 5% 5.5% 6%

RadioButton Example: RadioButtons having the same name belong to one group 10 year 15 year 30 year

Enter PV: Select Rate: 4% 4.5% 5% 5.5% 6% 6.5% 7% Select Year: 10 year 15 year 30 year Future Value: Note: We can assign an id to a HTML tag (element).

HTML Tags and Events Link : click, mouseOver, mouseOut Image : abort(loading is interrupted), error, load. Area : mouseOver, mouseOut Body : blur, error, focus, load, unload Frameset: blur, error, focus, load, unload Frame: blur, focus Form: submit, reset Textbox, Text area: blur, focus, change, select Button, Radio button, check box: click List: blur, focus, change

Event Handler Event handler name: on + event name – Ex. onClick Calling a handler: – onClick="CompSumJS()“ – onClick="window.alert('you click me')" – Note: single quote/double quote

Example of Event Handler <!-- function showSum(){ num1=parseFloat(window.prompt("Enter Num1: ")); num2=parseFloat(window.prompt("Enter Num2: ")); sum=num1+num2; window.alert("The sum is: " + eval(num1+num2)); window.alert("The sum is: " + sum); } -->

Form Datalist Control

Browser Object Model

Window Object The Window object represents a Web browser window. Properties: – window.status, window.defaultstatus – window.document, window.history, window.location. – Window.name Methods: – window.open (“url”, “name”, Options) Options: menubar=no, status=no, toolbar=no, etc. – window.close – window.alert(“string”) – window.prompt(“string”) – Window.focus, Etc. Try statements at:

Navigator Object The navigator object provides information about the browser. Properties: – Navigator.appName:browser name – Navigator.appCodeName: browser code name – Navigator.appVersion – Navigator.platform: the operating system in use.

Location Object Allows you to change to a new web page from within a script code. Properties: – Host, hostname, pathname – Href: current page’s URL address To reload a page: – location.reload() To open a page:Assign() – Ex. location.assign(URL)

Testing function openNew(){ site=window.prompt("enter url:"); window.open (site); location.assign(" }

History Object Maintain a history list of all the documents that have been opened during current session. Methods: – history.back() – history.forward() – history.go(): ex. History.go(-2)

Document Object The document object represents the actual web page within the window. Properties: – background, bgColor, fgColor, title, url, lastModified, domain, referrer, cookie, linkColor, etc. Ex. document.bgColor=“silver”; Methods: – Document.write (“string”) – Document.open, close

Accessing data entered on a form Using the future value form as an example: – Form name: fvForm – Textbox name: PV – Dropdown list: Rate – Radiobutton group name: Year

Accessing data entered on a form Textbox: – document.fvForm.PV.value Dropdown list: – document.fvForm.Rate.options[document.fvForm.R ate.selectedIndex].value Radiobuttons: if (document.fvForm.Year[0].checked) {myYear=10;} else if (document.fvForm.Year[1].checked) {myYear=15;} else {myYear=30;}

CheckBox document.LoanForm.checkBox1.checked

Alternative way using the id attribute document.getElementById(“PV").value

JavaScript Reference

Client Side Script ……..statements

JavaScript Variable Declaration var intrate, term, amount; Data Type: – Variant - a variable’s data type is determined when it is initialized to its first value. Variable scope: – Local: Variables declared in a function or procedure. – Global: Variables declared in the heading section, but not in a function or procedure. Variable name is case-sensitive. Note: We can use a variable without declare it.

Statements Statements: – End with “;” – Block of code: { } Comments: – Single-line comment: //comment – Block comment: /* comment comment */

Arrays var arrayName = new Array(array size); var Pet = new Array(2); Pet[0]=“dog”; Pet[1]=“cat”; Pet[2]=“bird”;

Operators Arithmetic operators: +, -, *, /, Math.pow(x,y), etc. Math is an object with many methods such as round(x), random(), sqrt(x), ceil(x), floor(x), etc. Comparison operators: = =, !=,, = Logical operators: &&, ||, !

Formula to Expression

IF Statements JS:if (condition) { statements; } else { statements; } if (document.fvForm.Year[0].checked) {myYear=10;} else if (document.fvForm.Year[1].checked) {myYear=15;} else {myYear=30;}

Switch Case Statements switch(varable name) { case value1: statements; break; case value2: statements; break; … default: statements; break; }

Loop Structures 1.while (condition) { statements; } 2. for (var I = 0; I<5;I=I+1){ statements; } Note: Use Break statement to exit loop earlier. Ex. Break ;

JavaScript’s Conversion Functions parseFloat:for conversion to a floating-point number: – Ex. parseFloat('77.3') -> 77.3 parseInt: for string-to-integer conversion – Ex. parseInt('123.45') -> 123 toString(), toFixed(n) example: Price=5; Qty=10; Amount=Price*Qty; Document.write (Amount.toString()); Document.write (Amount.toFixed(2)); eval strVar = “5”; numVar = eval(strVar) Eval(Price*Qty)

Try Catch try { //Run some code here } catch(err) { //Handle errors here }

window.prompt: similar to VB’s inputBox window.alert: like MessageBox function showSum(){ num1=parseFloat(window.prompt("Enter Num1: ")); num2=parseFloat(window.prompt("Enter Num2: ")); sum=num1+num2; window.alert("The sum is: " + eval(num1+num2)); window.alert("The sum is: " + sum); }

JavaScript Functions Defining functions – function functionName(arg1,..,argN){ Statements; return return value; – } Note: 1. The arguments are optional. 2. The return statement is optional. A JavaScript function is not required to return a value.

Example: JavaScript to Compute the sum of two values <!-- function ComputeSum(){ n1=document.testForm.num1.value; n2=document.testForm.num2.value; document.testForm.valueSum.value=eval(n1)+eval(n2); } -->

JavaScript to compute the future value

Enter PV: Select Rate: 4% 4.5% 5% 5.5% 6% 6.5% 7% Select Year: 10 year 15 year 30 year Future Value: Note: We can assign an id to a HTML tag (element).

<!-- function ComputeFV(){ //myPV=eval(document.fvForm.PV.value); myPV=parseFloat(document.fvForm.PV.value); //myRate=eval(document.fvForm.Rate.options[document.fvForm.Rate.selectedIndex].value); myRate=parseFloat(document.fvForm.Rate.options[document.fvForm.Rate.selectedIndex].va lue); if (document.fvForm.Year[0].checked) {myYear=10;} else if (document.fvForm.Year[1].checked) {myYear=15;} else {myYear=30;} fv=myPV*Math.pow(1+myRate,myYear); document.fvForm.FV.value=fv.toString(); } --> Code Example

Using document.getElementById Enter PV: 4% 5% 6% 7% 8% Select Year: 10 year 15 year 30 year Future Value:

function ComputeFV(){ //myPV=eval(document.fvForm.PV.value); myPV=parseFloat(document.getElementById("PV").value); myRate=parseFloat(document.getElementById("Rate").value); if (document.getElementById("Year10").checked) {myYear=10;} else if (document.getElementById("Year15").checked) {myYear=15;} else {myYear=30;} fv=myPV*Math.pow(1+myRate,myYear); document.fvForm.FV.value=fv.toString(); }

Years to Reach Goal

Code Example <!-- function ComputeJS(){ pv=eval(document.testForm.txtPv.value); rate=eval(document.testForm.txtRate.value); goal=eval(document.testForm.txtGoal.value); fv=0; for (i=1; i<=9999; ++i){ fv=pv*Math.pow(1+rate,i); if(fv>=goal){ document.testForm.yearNeeded.value=i; break; } -->

Working with Table Straight Line Depreciation Table

HTML Table Tag : id and name attributes – : Table Heading section : new row – : column heading – : data rows

HTML Form Code Straight Line Depreciation Table Enter Property Value: Enter Property Life: Year Value at BeginYr Dep During Yr Total to EndOfYr

Table/Row/Cell Object Table object: – Properties: rows: collection of data rows (including the header row) – rows.length: number of rows – 0-based index – Methods: InsertRow(index) deleteTow(index) Data Row object method: – insertCell(index) Cell object: – innerHTML property: cell’s data

HTML element’s innerHTML property Each HTML element has an innerHTML property that defines both the HTML code and the text that occurs between that element's opening and closing tag. By changing an element's innerHTML after some user interaction, you can make much more interactive pages. Assigning a value: – document.getElementById(“p”).innerHTML = 5;

function showTable(){ value=eval(document.depForm.pValue.value); life=eval(document.depForm.pLife.value); depreciation = value / life; var table = document.getElementById('depTable'); var totalDepreciation=0; for(var i = table.rows.length - 1; i > 0; i--) { table.deleteRow(i); } for (count = 1; count <= life; count++) { var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell0 = row.insertCell(0); cell0.innerHTML=count; var cell1 = row.insertCell(1); cell1.innerHTML="$" + value.toFixed(2); var cell2 = row.insertCell(2); cell2.innerHTML="$" + depreciation.toFixed(2); totalDepreciation += depreciation; var cell3 = row.insertCell(3); cell3.innerHTML="$" + totalDepreciation.toFixed(2); value -= depreciation; }

Validating Data: The property value and life boxes cannot be blank <!-- function Validating(){ var Valid; Valid=true; if (document.depForm.pValue.value=="" ||document.depForm.pLife.value=="") {Valid=false;} if (Valid==false) {alert("Property value or life cannot contain blank");} else {showTable();} }--> Note: the button’s onClick event will call the Validating function:

Useful function for Validation isNaN(): The isNaN() function determines whether a value is an illegal number (Not-a- Number). This function returns true if the value is NaN, and false if not.