Introduction to JavaScript + More on Interactive Forms.

Slides:



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

NAMEd anchors Enabling users to jump to specific points within Web documents.
DT211/3 Internet Application Development JSP: Processing User input.
MSc. Publishing on WWW JavaScript. What is JavaScript? A scripting language devised by Netscape Adds functionality to web pages by: Embedding code into.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
NAMEd anchors Enabling users to jump to specific points within Web documents.
Creating Web Page Forms
1 CS101 Introduction to Computing Lecture 12 Interactive Forms (Web Development Lecture 4)
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Interactive Form 1 Edited By; L.Maha AlAjmi. Revision 2 We learnt how to extend our Web pages by adding a few more tags Specifically, we discussed various.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
1 CS101 Introduction to Computing Lecture 32 Event Handling (Web Development Lecture 11)
4-Sep-15 HTML Forms Mrs. Goins Web Design Class. Parts of a Web Form A Form is an area that can contain Form Control/Elements. Each piece of information.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
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.
Introduction to JavaScript. JavaScript Facts A scripting language - not compiled but interpreted line by line at run-time. Platform independent. It is.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Project Four Forms Discuss form processing Describe the difference between client-side and server-side form processing Add a horizontal rule to a Web page.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
Advanced Web Design Scripting Tutorial Chapters. Scripting Intro The scripting part of the forthcoming Advanced Web Design textbook introduces you to.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
1 CS101 Introduction to Computing Lecture 18 Objects, Properties, Methods (Web Development Lecture 6)
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
1 VU. 2 CS101 Introduction to Computing Lecture 15 More on Interactive Forms (Web Development Lecture 5)
1 CS428 Web Engineering Lecture 11 Client Side Scripting (JavaScript - I)
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.
JSP Java Server Pages Softsmith Infotech.
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.
Lecture # 6 Forms, Widgets and Event Handling. Today Questions: From notes/reading/life? Share Personal Web Page (if not too personal) 1.Introduce: How.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
HTML Forms. Today’s Lecture We will try to understand the utility of forms on Web pages We will find out about the various components that are used in.
Chapter 8 Collecting Data with Forms. Chapter 8 Lessons Introduction 1.Plan and create a form 2.Edit and format a form 3.Work with form objects 4.Test.
JavaScript. During the last lecture We looked at the utility of forms on Web pages We found out about the various components that are used in a form We.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
76 © 1998, 1999, 2000 David T. Gray, Howard Duncan, Jane Kernan Frames When displaying information in a browser, it is sometimes useful to divide the display.
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.
Introduction to JavaScript CS101 Introduction to Computing.
44238: Dynamic Web-site Development Client Side Programming Ian Perry Room:C48 Extension:7287
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 Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
Introduction to JavaScript Objects, Properties, Methods.
By Tharith Sriv. To write a web page you use: HHTML (HyperText Markup Language), AASP (Active Server Page), PPHP (HyperText Preprocessor), JJavaScript,
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Scripting Languages Client Side and Server Side. Examples of client side/server side Examples of client-side side include: JavaScript Jquery (uses a JavaScript.
Form Processing Week Four. Form Processing Concepts The principal tool used to process Web forms stored on UNIX servers is a CGI (Common Gateway Interface)
 Web pages originally static  Page is delivered exactly as stored on server  Same information displayed for all users, from all contexts  Dynamic.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
INTRODUCTION JavaScript can make websites more interactive, interesting, and user-friendly.
Web Programming Overview. Introduction HTML is limited - it cannot manipulate data How Web pages are extended (include): –Java: an object-oriented programming.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
JavaScript is a programming language designed for Web pages.
Section 17.1 Section 17.2 Add an audio file using HTML
During the last lecture we discussed Functions & Variable Scope
PHP / MySQL Introduction
During the last lecture we continued our discussion on Interactive Forms
JavaScript Form Validation
JavaScript Basics What is JavaScript?
Presentation transcript:

Introduction to JavaScript + More on Interactive Forms

In Today’s Lecture … We will learn ways of adding more interactivity to forms We will get our first taste of JavaScript – the object-based language that we will be employing throughout the rest of the Web development part of this course Last time we mentioned server-side scripts; today we will write (simple) client-side scripts in JavaScript

Let’s take a look at a form that we constructed last time, and see how we can make it better

Let’s now review what happens when I enter all the required info and press the “Send ” button?

Info contained in the form Acknowledgement Message to the receiver’s address User’s Computer Web Server Server-Side Script Browser

This is what happens when the form is filled correctly. What if the form is filled incorrectly? What if the users leaves one of the essential fields, blank? What if the user enters an illegal address? Examples: –imran2umt.edu.p

A Reasonable Scenario When the “Send ” button is clicked, the browser sends the data collected through the form to a script running on the Web server That server-side script: –receives that data –analyzes it –discovers the missing or incorrect data –sends a message back to the user’s browser stating the problem and asks the user to re-send

This process … That is the process of the user: –Filling the incomplete/incorrect data –Sending it to the server –Receiving the response back from the server –Correcting and resending is quite time-consuming and uses the server’s resources to help the user correct his mistakes It can really bog down the server if a large number of users are using that Web server

Client-Side Scripting is a viable alternate In this technique, one uses the user’s browser to checking the form data If data is missing or is incorrect, the browser can prompt the user to take corrective action This way, the form data is sent to the server-side script only after it has been established that the collected data is complete and correct

Server-Side Scripts: Review Are programs that reside on Web servers Receive info that a user enters in a form Process that info and take appropriate action Examples: –CGI scripts on Unix servers –ASP scripts on Windows servers

New Concept: Client-Side Scripts Small programs that are a part of the Web page and run on the user’s (client’s) computer They interact with the user to collect info or to accomplish other tasks Once it has been collected, they may help pass the collected info on to a server-side script We’ll use JavaScript to do client-side scripting. However, there are many other languages that can be used for that purpose, e.g. VBScript

Advantages of Client-Side Scripting Reduced server load as it does not have to send messages to the user’s browser about missing or incorrect data Reduced network traffic as the form’s data is sent only once instead of many to’s and fro’s

Disadvantages Client-side scripts do not work with all browsers Some user intentionally turn scripting off on their browsers This increases the complexity of the Web page, as it now has to support both situations: browsers with scripting capability, and those not having that capability

A Simple Example of Client-Side Scripting

Code for the simple “Send ” button as was described during the last Web development lecture

Additional JavaScript code for the smart “Send ” button that would not allow itself to be clicked if the “From” text field is left blank

Event Handler

This is one way of including JavaScript code in an HTML document – that is, including a short JavaScript segment as part of an HTML tag There are a few others as well. Let’s now find out about another. But before we do that … … let’s just make clear why we are interested in including JavaScript in our Web pages

Why JavaScript? HTML is great for static Web pages; however, supports only rudimentary interactivity through forms and hyperlinks JavaScript can be used (along with HTML) to develop more interactive content for the Web

What is JavaScript? A programming language specifically designed to work with Web browsers It is designed to be used for developing small programs – called scripts – that can be embedded in HTML Web pages JavaScript: –Is an interpreted language –Supports event-driven programming –Is object-based

Object Based? Everything that JavaScript manipulates, it treats as an object – e.g. a window or a button An object has properties – e.g. a window has size, position, status, etc. Properties are modified with methods – e.g. a resize a window with resizeTo(150, 200)

Back to our example …

checkForm() JavaScript understands onMouseOver – it is one of the pre-defined keywords in JavaScript However, the case for checkForm() is different A checkForm() function does not exist in JavaScript. Therefore, we will have to define it ourselves It can either be defined in the HEAD portion or BODY portion. We will do it in the HEAD.

Send an function checkForm() { if ( document.send .sender.value.length < 1) { window.alert( “Empty From field! Please correct” ); } } … body content … JavaScript code enclosed in the new, HTML tags

We have looked at 2 techniques for embedding JavaScript code in a Web page: 1. Put the code in the tag for the “Send ” button - as was shown to you earlier 2. Put the checkForm() code in the HEAD portion & put the onMouseOver=“checkForm()” attribute in the tag for the “Send ” button Both perform the required function satisfactorily. Q: Which of two techniques is better?

The “put all code in the tag” technique seems to require less code For very short scripts, “all code in the tag” works well. However, this technique does not work when one needs to put multiple script statements in the same tag The “code in the HEAD portion” is more general-purpose, and the right choice for developing larger JavaScript scripts

Today we checked if the “From” field of the form was empty How can we modify the JavaScript code for checking if the “To” field is empty as well? How about checking all four fields? How about checking if the addresses given in the “From” and “To” fields are legal addresses? Please try thinking about those possibilities?

In Today’s Lecture … We learnt ways of constructing forms that were a bit more interactive We got our first taste of JavaScript – the object-based language that we will be employing throughout the rest of the Web development part of this course Last time we mentioned server-side scripts; today we wrote (simple) client- side scripts in JavaScript