1 More JavaScript, HTML Forms, CGI Scripts Tom Horton Alfred C. Weaver CS453 Electronic Commerce.

Slides:



Advertisements
Similar presentations
HTML Forms. collect information for passing to server- side processes built up from standard widgets –text-input, radio buttons, check boxes, option lists,
Advertisements

JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
SE-2840 Dr. Mark L. Hornick 1 HTML input elements and forms.
JavaScript Forms Form Validation Cookies CGI Programs.
Creating Web Page Forms. Objectives Describe how Web forms can interact with a server-based program Insert a form into a Web page Create and format a.
Tutorial 6 Working with Web Forms
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.
Gathering Requirements What do users want?. Information Gathering Techniques Surveys Interviews Focus Groups.
Forms Describe common uses of forms on web pages
Python and Web Programming
USER INTERACTIONS: FORMS
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
Creating Web Page Forms
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Working with Forms in JavaScript (NON-audio version) © Dr. David C. Gibbs
Tutorial 6 Forms Section A - Working with Forms in JavaScript.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
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.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
XP Tutorial 6New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Creating Web Page Forms Designing a Product Registration Form Tutorial.
XP Tutorial 6New Perspectives on HTML and XHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
Web111a_chapt06.ppt HTML: Section 6 Forms HTML tags: define data input and/or output Define the Input and/or Output on the web page Do not process the.
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.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
Server-side Scripting Powering the webs favourite services.
Internet / Intranet Fall 2000 Class 7. Brandeis University Internet/Intranet Spring Class 7 Agenda Project / Homework Discussion Forms Validating.
Internet / Intranet CIS-536 Class 7. 2 HTML Forms A Method to Allow Users to Pass Information to a CGI Script Forms Allow Information to Be Entered Via:
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
Web Interfaces, Forms & Databases Databases Snyder p HTML Basics Snyder p JavaScript Snyder Chapter 18.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
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.
Website Development with PHP and MySQL Saving Data.
HTML Forms.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
7 Chapter Seven Client-side Scripts. 7 Chapter Objectives Create HTML forms Learn about client-side scripting languages Create a client-side script using.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
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.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
Scripting Languages Client Side and Server Side. Examples of client side/server side Examples of client-side side include: JavaScript Jquery (uses a JavaScript.
©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.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
 Web pages originally static  Page is delivered exactly as stored on server  Same information displayed for all users, from all contexts  Dynamic.
HTML Forms.
Week 10: HTML Forms HNDIT11062 – Web Development.
Basic Webpage Design HTML Forms. Objectives Learn how to use HTML to create a form. Explain the concept of forms Know the difference of GET and POST Discuss.
Creating Forms on a Web Page. 2 Introduction  Forms allow Web developers to collect visitor feedback  Forms create an environment that invites people.
Copyright (c) 2004 Prentice-Hall. All rights reserved. 1 Committed to Shaping the Next Generation of IT Experts. Project 6: Creating XHTML Forms Kelly.
HTML III (Forms) Robin Burke ECT 270. Outline Where we are in this class Web applications HTML Forms Break Forms lab.
HTML Structure II (Form) WEEK 2.2. Contents Table Form.
Ashima Wadhwa Java Script And Forms. Introduction Forms: –One of the most common Web page elements used with JavaScript –Typical forms you may encounter.
XP Tutorial 6New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
Tutorial 6 Working with Web Forms
Chapter 5 Validating Form Data with JavaScript
How to Write Web Forms By Mimi Opkins.
Presentation transcript:

1 More JavaScript, HTML Forms, CGI Scripts Tom Horton Alfred C. Weaver CS453 Electronic Commerce

2 Overview HTML Forms JavaScript and Forms Event model and events CGI Programming for server-side scripts

3 HTML Forms Provide GUI-like components in your page Inputs: buttons, textboxes, radio buttons, selections Output fields: text boxes etc. Can send information to the server Can be accessed by JavaScript code on the client-side Tutorial with on-line fiddling:

4 Basics of Forms A form element: Inside: Used to define a large number of common inputs Empty element (no end-tag (Except the following…) multiple lines of text List of choices in pop-up or scrollable list

5 Common Form Element Attributes On the tag NAME=“symbolic name” Used in JavaScript to reference form and what’s inside it METHOD=“…” and ACTION=“…” More on these later On other tags: NAME=“symbolic-name” Required for almost all input tags (not buttons) Used by JavaScript and when sending info to server

6 Use begin and end tags Attributes: ROWS=“…” (four by default) COLS=“…” (40 characters by default) Default text What’s between and

7 types Specify with TEXT: line of text PASSWORD: line of text that hides what’s typed CHECKBOX: yes/no RADIO: use >1 for mutually exclusive choice SUBMIT: button that initiates processing Other attributes needed for each of these Don’t forget NAME=“…”

8 Single Line of Text Attributes: NAME, optionally SIZE, MAXLENGTH, VALUE Default text defined by VALUE Example:

9 A Checkbox Attributes: NAME, optionally CHECKED, VALUE What’s is the value when it’s checked? VALUE attribute specifies this CHECKED: initially displays checked Example:

10 Radio buttons Attributes: NAME, optionally CHECKED, VALUE Mutually exclusive checkboxes None or one can be checked, not more than one Use same NAME value to “group” a set of these! Note: when retrieving these in JavaScript, you get back an array of values CHECKED if one checked by default Example: First choice Second choice

11 Submit and Reset Buttons One of two button types TYPE=“RESET” clears all data in the form Attributes: optionally VALUE, NAME VALUE: name displayed, and what’s sent to the server (more later). “Submit Query” is default Example:

12 Aside: More General Buttons Also a element that needs an end-tag Text (or images) goes inside the element Attributes: NAME, DISABLED, TYPE (push, reset, submit), VALUE Submit buttton with image: Save Example that links to a page: Change Password

13 Multiple Selections element with Need to organize this like a list, so empty element not enough Attributes: NAME, optionally SIZE, MULTIPLE Use for choices inside Attributes: VALUE, optionally SELECTED (for default)

14 Examples Volvo Saab Pizza Pasta

15 Layout and Design Tips In HTML you don’t have full control over layout Check for resizing, wrapping issues Use line breaks and paragraphs Use lists or (descriptive lists) Multiple forms in one page Each with a SUBMIT button

16 And Then What Happens to that Input? Again, two ways forms often used JavaScript functions process form data Sent back to the server for processing No JavaScript involved Something waiting on the back-end though

17 JavaScript and Forms We have an event model that lets us: Associate an event-handler (JavaScript function) with… An event (e.g. value changed, got focus, hit submit, etc.) that happens on… A particular HTML element E.g. See lists of events here:

18 Some Nice Events ONCLICK Attach to particular element, or Note: in HTML/JavaScript code, probably better to put event names in lower-case Others: ONLOAD: when an element is loaded Cursor tracking: ONMOUSEMOVE, ONMOUSEOVER, ONMOUSEOUT Input fields: ONFOCUS, ONBLUR (loses focus)

19 and Events Common to use ONSUBMIT to call function when submit button sent And before FORM takes its ACTION (more on ACTION soon, I promise) Method may: Validate fields by accessing form-input elements’ values Use alert-boxes to confirm submission Etc.

20 More on ONSUBMIT If function specified with ONSUBMIT returns true or false If true, form ACTION taken If false, form ACTION not taken In general, JavaScript function can window.event.returnValue = false; Which cancels the default action of an event on an element

21 ACTIONs associated with Forms Finally! The FORM element typically has these attributes: ACTION=“…” that points to a URL METHOD=“…” with value GET or POST ACTION points to a script (on the server) to process form data values Some special uses here METHOD: usually POST More details later when we talk about CGI

22 mailto: and ACTION mailto: -- special URL that pops up a compose- window in a browser If supported by your browser Nice for testing in any case Example:

23 Static Web Page Delivery Web Server Client 1 Author writes HTML 2 Client requests page 3 Web server locates.htm file HTML stream returned to browser 4 5 Browser processes page

24 Client-side vs. Server-side Processing Computer processing can happen in two locations Server: Accepts request, finds page, sends it Client: Gets HTML (or more?) from net, processes it, displays it Advanced things can happen on one or both sides

25 Many Technology Choices Client-Side Technologies: Scripting languages: JavaScript, VBScript Java applets XML Server-Side Alternatives: CGI Active Server Pages (ASP) PHP Java Server Pages (JSP) ColdFusion

26 Client-side Scripting Languages What’s a Scripting Language? Not a full-scale programming language Usually for a special purpose Usually interpreted “on the fly” Client-side scripting languages File contains script mixed in with HTML code Sent from server to browser Run “inside” the browser before HTML is displayed Makes HTML pages dynamic, customized

27 Dynamic Web Page Delivery Web Server Client 1 Author writes instructions 2 Client requests page 3 Web server locates instructions file HTML and script are returned to browser 5 6 Browser displays HTML 4 Web browser processes script to create HTML

28 Server-side processing: Overview Lots of processing can happen on the server before returning a webpage to the client Run programs in a scripting language (e.g. ASP) Manage sessions Cookies Sessions, shopping baskets, log-ins, etc. Database processing But the following slide shows when this processing happens At Step 4!

29 Server-side Dynamic Page Delivery Web Server Client 1 Author writes instructions 2 Client requests page 3 Web server locates instructions file HTML stream returned to browser 5 6 Browser processes page 4 Web server processes instructions to create HTML

30 CGI Scripts When not using mailto:, what happens? Simplest (oldest) approach: CGI (Common Gateway Interface) ACTION points to a script on the server That script can process form input values It generates HTML that it writes which is then displayed back in the browser On-line:

31 Scripts Scripts written in: UNIX Shell, perl, C, etc. Perl and other scripting languages have rich libraries to help Scripts stored where? Depends on your webserver Apache on UNIX: central location and per- user scripts

32 GET vs POST If you used POST Form data sent back with the URL defining the script and you read it from standard-input If you used GET Form data sent back in a separate environment variable accessible in the web-server What this means: don’t care since… Use a library call to grab values E.g. in Perl: cgi-lib.pl which provides a &ReadParse function that creates a map (associative array) with form name/value pairs

33 CGI in Practice Lots of tips and tricks Lots of how-to on the Web And in our Virtual Labs Do the unit on perl See information there on CGI Download perl and Apache webserver Windows: Mac: MAMP