Web Site Design and Development Lecture 22 CS 0134 Fall 2018 Tues - - PowerPoint PPT Presentation

web site design and development lecture 22
SMART_READER_LITE
LIVE PREVIEW

Web Site Design and Development Lecture 22 CS 0134 Fall 2018 Tues - - PowerPoint PPT Presentation

Web Site Design and Development Lecture 22 CS 0134 Fall 2018 Tues and Thurs 1:00 2:15PM Form Forms that allow users to submit information to us are created with the form element Attributes id: the id of the form action:


slide-1
SLIDE 1

Web Site Design and Development Lecture 22

CS 0134 Fall 2018 Tues and Thurs 1:00 – 2:15PM

slide-2
SLIDE 2

2

Form

  • Forms that allow users to submit information to us are

created with the form element

  • Attributes

– id: the id of the form – action: the URL that the form will be submitted to – method: The HTTP method used to submit the data; can be set to

“get” or “post”. The default is “get”

– target: where the action URL will be opened. Like with <a>, setting

this to “_blank” will open the page in a new tab.

  • Within the form element, you place any number of form

fields or buttons, known as controls.

slide-3
SLIDE 3

3

Form example

<form id=”my-form” action=”upload.php” method=”post”> <!-- Form controls --> </form>

slide-4
SLIDE 4

4

Input

  • The input element is used for the majority of form controls
  • Common Attributes

– type: sets the type of control – id: the id of the input – name: a name for the element, used by client-side and server-side scripts – disabled: boolean attribute that sets if a control is disabled; data for that

control is not submitted with the form

– readonly: boolean attribute that sets if a control is readonly; data for that

form is submitted with the form

  • Boolean attributes are used by just using the attribute name

without a value

slide-5
SLIDE 5

5

Input example

<input type=”text” id=”field” name=”field” disabled>

slide-6
SLIDE 6

6

Buttons

  • Buttons can be created in two ways, with

the input element or with the button element

  • The main difference between using input

and button is that input allows the button to just contain plain text or an image while button element allows you to use HTML in the button.

slide-7
SLIDE 7

7

Buttons continued

  • Attributes for both input and button

– type: the type of button. This can be set to:

  • submit: submits the form to the action using the method
  • reset: resets the form fields to their default values
  • button: specifies a generic button that can be tied to JavaScript
  • image: specifies a button that uses an image

– value: the text on the button and the value submitted with the

form

  • For the image button type, you can also use the

attributes src, alt, height and width like you would the img element

slide-8
SLIDE 8

8

Button examples

<input type=”submit” value=”Search”> <button type=”submit”> <img src=”spyglass.png” alt=”Spyglass”>Search </button>

slide-9
SLIDE 9

9

Text inputs

  • Text inputs include inputs of type=”text”,

type=”password” and type=”hidden”

  • For the text and password types, a text box

is created that the user can use to input text

  • For the password type, the text that is input

is obscured by bullets or asterisks.

  • For the hidden type, no text box is created

and the value is hidden from the user.

slide-10
SLIDE 10

10

Text inputs continued

  • Attributes

– value: the default value of the text input – maxlength: how many characters can be entered in the

field

– size: the width of the text box in units of the average

width of the font. It is better to use CSS

– autofocus: boolean attribute that tells the browser to give

this input focus when the page is loaded

– placeholder: placeholder text for the field that will

disappear when a user’s cursor enters the text box

slide-11
SLIDE 11

11

Text input examples

<input type=”text” id=”username” name=”username” placeholder= “Enter Username” autofocus> <input type=”hidden” id=”prodId” name=”prodId” value=”1001”>

slide-12
SLIDE 12

12

Check box <input type=”checkbox”>

  • The <input type=”checkbox”> element is used

to create check boxes

  • Attributes

– name: name of the check box that can be used by

client-side and server-side scripts

– value: the value submitted if the check box is checked – checked: boolean attribute that sets if the check box

should be checked when the page is loaded. This is considered the default state of the check box

slide-13
SLIDE 13

13

Check box example

<input type=”checkbox” name=”agree” id=”agree” value=”yes”>Do you agree to the terms and conditions?<br>

slide-14
SLIDE 14

14

Radio button <input type=”radio”>

  • The <input type=”radio”> element is used to create radio

buttons

  • Attributes

– name: name of the radio button that can be used by client-side and

server-side scripts

– value: the value submitted if the radio button is checked – checked: boolean attribute that sets if the radio button should be checked

when the page is loaded. This is considered the default state of the radio button

  • Radio buttons are grouped by giving them all the same name
  • attribute. Only one option of a group of radio buttons can be

checked at a time.

slide-15
SLIDE 15

15

Radio button example

<input type=”radio” name=”agree” id=”yes” value=”yes”>Yes<br> <input type=”radio” name=”agree” id=”no” value=”no”>No<br>

slide-16
SLIDE 16

16

Select

  • The select element is used to create drop-

down boxes

  • The children of a select element are made

up of one or more optgroup and option elements

  • By default, the first option element is

selected as the value of the select element

slide-17
SLIDE 17

17

Option

  • The option element is used to create an
  • ption for a select element
  • Attributes

– value: the value submitted if the option is selected – selected: tells the browser that this option should

be selected when the page loads

slide-18
SLIDE 18

18

Optgroup

  • The optgroup element groups option

elements under a label in a select element

  • Attribute

– label: the label to be shown before the group of

  • ption elements
slide-19
SLIDE 19

19

Select example

<select id=”states” name=”states” <optgroup label=”East”> <option value=”PA”>Pennsylvania</option> <option value=”NY”>New York</option> </optgroup> <optgroup label=”West”> <option value=”OR”>Oregan</option> <option value=”CA”>California</option> </optgroup> </select>