LOGO FORMs in HTML CHAPTER 5 Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC229 Client-Side Internet and Web Programming Prepared by: R. Kansoy
5. FORMs in HTML 2 Used to collect information from people viewing your site The tag is used to create an HTML form. FORM element Attributes METHOD attribute indicates the way the Web server will organize and send you form output. METHOD = “post” in a form that causes changes to server data. METHOD = “get” in a form that does not cause any changes in server data. ACTION attribute Path to a script Web server: machine that processes browser requests.
5. FORMs in HTML 3 HTML forms are used to pass data to a server. A form can contain input elements like; text fields, checkboxes, radio buttons, submit buttons and more.. A form can also contain select lists, textarea, fieldset, legend, and label elements.
5. FORMs in HTML 4 The Input Element The most important form element is the input element. An input element can vary in many ways, depending on the type attribute. An input element can be of type text, checkbox, password, radio, submit, reset and more..
5. FORMs in HTML 5 The Input Element INPUT element Attributes: TYPE (required) – Defines the usage of the INPUT element – Hidden inputs always have TYPE = “hidden” NAME provides a unique identification for INPUT element VALUE indicates the value that the INPUT element sends to the server upon submission SIZE – For TYPE = “text”, specifies the width of the text input, measured in characters MAXLENGTH – For TYPE = “text”, specifies the maximum number of characters that the text input will accept
First name: Last name: First name: Last name: 5. FORMs in HTML Text Fields defines a one-line input field that a user can enter text into: 6 How the HTML code above looks in a browser: Note: The form itself is not visible. Also note that the default width of a text field is 25 characters.
Password: 5. FORMs in HTML Password Field defines a password field: 7 How the HTML code above looks in a browser: Note: The characters in a password field are masked (shown as asterisks or circles).
Male Female 5. FORMs in HTML Radio Buttons Radio buttons let a user select ONLY ONE of a limited number of choices. defines a radio button. CHECKED attribute indicates which radio button is selected initially 8 How the HTML code above looks in a browser:
5. FORMs in HTML Checkboxes Checkboxes let a user select NONE/ONE/MORE options of a limited number of choices. defines a checkbox. Used individually or in groups Each checkbox in a group should have same NAME Make sure that the checkboxes within a group have different VALUE attribute values Otherwise, browser will cannot distinguish between them CHECKED attribute checks boxes initially 9
I have a bike I have a car I have a bike I have a car 5. FORMs in HTML Checkboxes 10 How the HTML code above looks in a browser:
Username: 5. FORMs in HTML Submit Button defines a submit button. A submit button is used to send form data to a server. The data is sent to the page specified in the form's action attribute. The file defined in the action attribute usually does something with the received input. VALUE attribute changes the text displayed on the button (default is “Submit”) 11 How the HTML code above looks in a browser: NOTE: If you type some characters in the text field above, and click the "Submit" button, the browser will send your input to a page called "html_form_action.asp". The page will show you the received input
Username: Password: Username: Password: 5. FORMs in HTML Reset Button defines a reset button. A reset button is used to clear all the entries user entered into the form. VALUE attribute changes the text displayed on the button (default is “Reset”) 12 How the HTML code above looks in a browser:
ITEC 229 ITEC FORMs in HTML TEXTAREA Inserts a scrollable text box into FORM ROWS and COLS attributes specify the number of character rows and columns 13 How the HTML code above looks in a browser:
5. FORMs in HTML SELECT Places a selectable list of items inside FORM Include NAME attribute Add an item to list Insert an OPTION element in the … tags Closing OPTION tag optional SELECTED attribute applies a default selection to list Change the number of list options visible Including the SIZE = “x” attribute inside the tag x number of options visible 14
5. FORMs in HTML SELECT 15 BMW Mercedes Audi BMW Mercedes Audi How the HTML code above looks in a browser:
5. FORMs in HTML EXAMPLE 1: 16 Forms Feedback Form Please fill out this form to help us improve our site. Name: Comments: Forms Feedback Form Please fill out this form to help us improve our site. Name: Comments:
5. FORMs in HTML EXAMPLE 1 (cont..) : Address: Things you liked: Site design Links Ease of use Images Source code Address: Things you liked: Site design Links Ease of use Images Source code
5. FORMs in HTML EXAMPLE 1 (output): 18
5. FORMs in HTML EXAMPLE 2: 19 Forms II Feedback Form Please fill out this form to help us improve our site. Name: Comments: Address: Forms II Feedback Form Please fill out this form to help us improve our site. Name: Comments: Address:
5. FORMs in HTML EXAMPLE 2 (cont..): 20 Things you liked: Site design Links Ease of use Images Source code How did you get to our site?: Search engine Links from another site Deitel.com Web site Reference in a book Other Things you liked: Site design Links Ease of use Images Source code How did you get to our site?: Search engine Links from another site Deitel.com Web site Reference in a book Other
5. FORMs in HTML EXAMPLE 2 (cont..): 21 Rate our site (1-10): Amazing:-) The Pits:-( Rate our site (1-10): Amazing:-) The Pits:-(
5. FORMs in HTML EXAMPLE 2 (output): 22
LOGOhttp://sct.emu.edu.tr/it/itec229 FORMs in HTML END of CHAPTER 5