Working with ‘checked’ items Checkboxes and Radio buttons

Slides:



Advertisements
Similar presentations
23-Aug-14 HTML/XHTML Forms. 2 What are forms? is just another kind of XHTML/HTML tag Forms are used to create (rather primitive) GUIs on Web pages Usually.
Advertisements

24-Aug-14 HTML Forms. 2 What are forms? is just another kind of HTML tag HTML forms are used to create (rather primitive) GUIs on Web pages Usually the.
Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
>> Introduction to HTML: Forms. Introduction to HTML 5 Important HTML Tags HTML tags and attributes Images Hyperlinks Lists –{ordered | unordered | definition}
Form Validation. Learning Objectives By the end of this lecture, you should be able to: – Describe what is meant by ‘form validation’ – Understand why.
PHP Workshop ‹#› Forms (Getting data from users).
Video, audio, embed, iframe, HTML Form
17/10/11. 2  The form element ( ) is used to include a number of form elements together so that they can be referenced by some other code in order to.
Forms cs105. More Interactive web-pages So far what we have seen was to present the information. (Ex: tables. Lists,….). But it is not enough. We want.
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.
Forms, Validation Week 7 INFM 603. Announcements Try placing today’s example in htdocs (XAMPP). This will allow you to execute examples that rely on PHP.
Tutorial #9 – Creating Forms. Tutorial #8 Review – Tables Borders (table, gridlines), Border-collapse: collapse; empty-cells: show; and rowspan, colspan.
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 What is a form.
Forms and Form Controls Chapter What is a Form?
CSE 382/ETE 334 Internet and Web Technology Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
JQuery and Forms – Part I. Learning Objectives By the end of this lecture, you should be able to: – Retrieve the values entered by a user into a form.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Forms Sangeetha Parthasarathy 02/05/2001. Introduction to Forms A form makes it possible to transform your web pages from text to graphics to interactive.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
Suzanne J. Sultan Javascript Lecture 2. Suzanne J. Sultan function What is a function> Types of functions:  Function with no parameters  Function with.
INTRODUCTORY Tutorial 8 Creating Forms. XP New Perspectives on Blended HTML, XHTML, and CSS2 Objectives Create an HTML form Create fields for text Create.
BBK P1 Module2010/11 : [‹#›] Forms (Getting data from users)
HTML Forms.
HTML and FORMS.  A form is an area that can contain form elements.  Form elements are elements that allow the user to enter information (like text fields,
1 HTML Forms
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
1 Review of Form Elements. 2 The tag Used in between tags.  Form elements(text control, buttons, etc.. ) goes here. OR  Form elements(text control,
HTML Forms a form is a container for input elements on a web page input elements contain data that is sent to the web server for processing.
Web Forms. Survey or poll Contact us Sign up for an newsletter Register for an event Submit comments or feedback about our site Log in to a members-only.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
+ FORMS HTML forms are used to pass data to a server. begins and ends a form Forms are made up of input elements Every input element has a name and value.
Copyright © Texas Education Agency, All rights reserved.1 Web Technologies Website Forms / Data Acquisition.
HTML Creating Forms on a Web Page. 2 Objectives  Discuss the process of creating a form  Distinguish between data input controls and text input controls.
HTML FORMS Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan. 1.
Lesson 16. Practical Application 1 We can take advantage of JavaScript and the DOM, to set up a form so that the first text box of a form automatically.
1 HTML Forms
Copyright (c) 2004 Prentice-Hall. All rights reserved. 1 Committed to Shaping the Next Generation of IT Experts. Project 6: Creating XHTML Forms Kelly.
Check Boxes. 2 Check boxes  Image from:  HTML:  Each box gets it's own.
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.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
Web Forms. Web Forms: A form allows our web visitors to submit information to us. Some examples uses for forms are to let the web user contact us, fill.
Lesson 5 Introduction to HTML Forms. Lesson 5 Forms A form is an area that can contain form elements. Form elements are elements that allow the user to.
HTML Basics (Part-3).
Web Forms.
Making your HTML Page Interactive
Web Forms.
Checkboxes, Select boxes, Radio buttons,
How to Write Web Forms By Mimi Opkins.
Introduction to HTML Forms and Servlets
Forms Web Design Ms. Olifer.
HTML Forms CSC 102 Lecture.
Retrieving information from forms
>> Form Data Retrieval in JavaScript
HTML/XHTML Forms 18-Sep-18.
Introducing Forms.
HTML Forms and User Input
Creating Form Elements
Creating Form Elements
Forms Data Entry and Capture
FORM OBJECT When creating an interactive web site for the Internet it is necessary to capture user input and process this input. Based on the result of.
Intro to Forms HTML forms are used to gather information from end-users. A form can contain elements like radio-buttons, text fields, checkboxes, submit.
HTML Forms 18-Apr-19.
JavaScript and Forms Kevin Harville.
Intro to Forms HTML forms are used to gather information from end-users. A form can contain elements like radio-buttons, text fields, checkboxes, submit.
© Hugh McCabe 2000 Web Authoring Lecture 8
Web Forms.
Making your HTML Page Interactive
Retrieving information from forms
Checkboxes, Select boxes, Radio buttons
Presentation transcript:

Working with ‘checked’ items Checkboxes and Radio buttons JavaScript Working with ‘checked’ items Checkboxes and Radio buttons

Learning Objectives By the end of this lecture, you should be able to: Determine in your JavaScript code whether or not a checkbox was checked. Determine in your JS code which button in a group of radio buttons was checked. Retrieve a value from a checkbox or radio button.

Retreiving info from form elements that contain ‘text’ Recall the document.getElementById('elementName').value code that we’ve used for textboxes, textareas, and, select boxes. Example: Suppose you have a select box called selNationality. To retreive the value you could type: var country = document.getElementById('selNationality').value; The value that gets retreived will be the one you encoded inside the <option> tag. Similarly, for text boxes and textareas, the value retrieved is the information that was typed in by the user.

Determining if a checkbox or radio buton is selected But what if there is no text? For example, what if you are simply working with a checkbox? Or a radio button? Answer: We use document.getElementById('element_name').checked

<script type="text/javascript"> function doStuff() { if ( document.getElementById('chkFirst').checked ) alert("Going in style!"); if ( document. getElementById('chkPet').checked) alert("Taking your pet!"); if ( document. getElementById('chkSpouse').checked ) alert("Taking your spouse"); } </script> <form id="travelOptions"> <input type="checkbox" id="chkFirst">First Class Only <br> <input type="checkbox" id="chkPet">Traveling with Pet <br> <input type="checkbox" id="chkSpouse">Traveling with Spouse <br> <input type="submit" onClick="doStuff()" > </form>

Retrieving the value of a radio button With things like text fields and select boxes, we must ultimately retrieve a 'value'. However, with checkboxes and radio buttons, this is not necessarily the case. That is, with things like checkboxes / radio buttons, we often only need to know if the box/button was checked. However, while your buttons and checkboxes do not necessarily have to have a value, it is often very useful to do so. If your button has a value, you can retrieve it using the familiar ‘.value’ syntax. Whether or not you choose to include a value is a matter of context in terms of how you set up your page. For example, in the following radio buttons, we have include a 'value' attribute: <input type="radio" name="favColor" id="radFavRed" value="red"> I love red. <input type="radio" name="favColor" id="radFavBlue" value="blue"> Big fan of blue. You could retrieve the value of this 'value' attribute as follows: var favoriteColor = document.getElementById("radFavRed").value; //favoriteColor will hold the value "red"

Retrieving the value of a radio button <input type="radio" name="favColor" id="radFavRed" value="red"> I love red. <input type="radio" name="favColor" id="radFavBlue" value="blue"> Big fan of blue. You could check to see which button was selected, and then retrieve the value of this 'value' attribute as follows: if document.getElementById("radFavRed").checked { favoriteColor = document.getElementById("radFavRed").value; alert("Favorite color is" + favColor); } else if document.getElementById("radFavBlue").checked

Example: radio_buttons_with_values.htm

Putting it all together… museum_admission.htm This program applies apply many of the other concepts of this course together. You should be able to replicate this program. You will very likely be asked to do something quite similar on your final exam.