Presentation is loading. Please wait.

Presentation is loading. Please wait.

HTML: Tables and Forms. Objectives Use tables to structure a webpage Use forms to collect user input –Method:Get, Post –Input –Select –Textarea.

Similar presentations


Presentation on theme: "HTML: Tables and Forms. Objectives Use tables to structure a webpage Use forms to collect user input –Method:Get, Post –Input –Select –Textarea."— Presentation transcript:

1 HTML: Tables and Forms

2 Objectives Use tables to structure a webpage Use forms to collect user input –Method:Get, Post –Input –Select –Textarea

3 In Class Keep 2 browser windows open. Try examples as we go along. Save notepad as html to desktop. (Double) click to see.

4 Tables To structure the page To arrange the elements on a page Contain rows of data cells

5 Defining a Table Structure The first step to creating a table is to specify the table structure: –the number of rows and columns –the location of column headings –the placement of a table caption Once the table structure is in place, you can start entering data into the table

6 ,, and Tags Graphical tables are enclosed within a two-sided tag that identifies the start and ending of the table structure Each row of the table is indicated using a two-sided (for table row) Within each table row, a two-sided (for table data) tag indicates the presence of individual table cells

7 Simple Table First Cell Second Cell Third Cell Fourth Cell –This creates a table with two rows and two columns

8 Simple Table Two rows and two columns two rows

9 Headings HTML provides the tag for table headings Text formatted with the tag is centered within the cell and displayed in a boldface font The tag is most often used for column headings, but you can use it for any cell that you want to contain centered boldfaced text

10 Table Caption The syntax for creating a caption is: caption text –alignment indicates the caption placement –a value of “bottom” centers the caption below the table –a value of “top” or “center” (newer) centers the caption above the table –a value of “left” or “right” (newer) place the caption above the table to the left or right

11 Table... enclose a table –... enclose a table row.... enclose a table data or cell.... enclose a table header. It’s a cell whose default is bold and centered. –... enclose a caption

12 Cell spacing The cellspacing attribute controls the amount of space inserted between table cells … –value is the width of the interior borders in pixels –the default cell spacing is 2 pixels

13 Cell spacing

14 Cell Padding The cellpadding attribute controls the space within the cells … –value is the distance from the table text to the cell border, as measured in pixels –the default cell padding value is 1 pixel

15 Cell Padding

16 Background Color You may specify a background color for all of the cells in a table, all of the cells in a row, or for individual cells: –color is either a color name or hexadecimal color value (to be discussed)

17 Attributes width – width of table in pixels or % of the browser window height – height of the table in pixels or % of the browser window cellpadding –the space between the cell border and the contents in pixels cellspacing – specifies the space between cells in pixels

18 Attributes align – left, center, right bgcolor – Background color of table border – –The width is in pixels. –The default is zero, or no border. –Including the border attribute without a value produces a 1 pixel border. See syllabus

19 Attributes align bgcolor

20 Cell Width To set the width of an individual cell, add the width attribute to either the or tags The syntax is: width=“value” –value can be expressed either in pixels or as a percentage of the table width –a width value of 30% displays a cell that is 30% of the total width of the table

21 Cell Height The height attribute can be used in the or tags to set the height of individual cells The height attribute is expressed either in pixels or as a percentage of the height of the table If you include more text than can be displayed within that height value you specify, the cell expands to display the additional text

22 Spanning Rows and Columns To merge several cells into one, you need to create a spanning cell A spanning cell is a cell that occupies more than one row or column in a table Spanning cells are created by inserting the rowspan and colspan attribute in a or tag. The syntax for these attributes is: … –value is the number of rows or columns that the cell spans in the table

23 Spanning Rows and Columns When a cell spans several rows or columns, it is important to adjust the number of cell tags used in the table row When a cell spans several rows, the rows below the spanning cell must also be adjusted

24 Spanning Rows and Columns This cell spans three columns This cell spans three rows

25 Row-Spanning Cell HTML code resulting table four table cells in the first row only three table cells are required for the second and third rows

26 Aligning Contents By default, cell text is placed in the middle of a cell, aligned with the cell’s left edge You can specify a different horizontal alignment for a or element align=“position” position is left, center or right

27 Attributes align – Horizontal alignment valign – Vertical alignment (top, middle, bottom) width – Width of cell in pixels or percentage of table width height – Height of cell in pixels or percentage of table height

28 Attributes colspan – Makes cell take up space of one or more cells rowspan – Makes cell take up space of one or more rows bgcolor

29 Placeholder Insert a no-breaking space in the empty cell. Row1 Col1 Row2 Col2 Row2 Col2

30 Nested Tables Tables can be created within the cell of another table. Carefully work on one table at a time.

31 Examples and homework See simple_calculator.html See table_example.html See form_border.html Do table assignment

32 HTML Forms http://www.ncsa.uiuc.edu/SDG/Software/M osaic/Docs/fill-out-forms/overview.htmlhttp://www.ncsa.uiuc.edu/SDG/Software/M osaic/Docs/fill-out-forms/overview.html Summary of HTML tags for forms and examples of simple forms www.webcom.com/html/tutor/forms Forms tutorial

33 HTML Forms HTML Forms were the first way for users to interact with the Web –controls (inputs) –form submission –form processing Forms collect user input … encloses a form

34 CGI Common Gateway Interface Programs that let HTML pages (on server) interact with the viewers (clients) via HTTP. Programs can send specific information. Programs get information from users. Written in C/C++, Java, Perl, UNIX scripts. Executed on the server

35 Forms E-commerce Feedback (surveys) Searching Faster More accurate Cheaper Virus free

36 GET -- this is the default method and causes the fill-out form contents to be appended to the URL. POST -- this method causes the fill-out form contents to be sent to the server in a data body rather than as part of the URL. ENCTYPE specifies the encoding for the fill-out form contents. This attribute applies only if METHOD is set to POST

37 Form Attributes Name Method –get -- this is the default method and causes the fill-out form contents to be appended to the URL. Use only when submit has no effect. e.g. pure query. –post -- this method causes the fill-out form contents to be sent to the server in a data body rather than as part of the URL.

38 Form Attributes Action : –The URL to which the data is sent (may be local) or –mailto: so the data just gets sent in an email. Enctype: the encoding for the fill-out form contents. This attribute applies only if the method is post.

39 Form Examples

40 Form Contents A Form may contain anything except another Form. Interface elements (controls): – input tags – select tags – textarea tags

41 Input Attributes The attributes to INPUT are as follows: TYPE must be one of: "text" (text entry field; this is the default) "password" (text entry field; entered characters are represented as asterisks) "checkbox" (a single toggle button; on or off) "radio" (a single toggle button; on or off; other toggles with the same NAME are grouped into "one of many" behavior) "submit" (a pushbutton that causes the current form to be packaged up into a query URL and sent to a remote server) "reset" (a pushbutton that causes the various input elements in the form to be reset to their default values) NAME is the symbolic name (not a displayed name -- normal HTML within the form is used for that) for this input field. This must be present for all types but "submit" and "reset", as it is used when putting together the query string that gets sent to the remote server when the filled-out form is submitted. VALUE, for a text or password entry field, can be used to specify the default contents of the field. For a checkbox or a radio button, VALUE specifies the value of the button when it is checked (unchecked checkboxes are disregarded when submitting queries); the default value for a checkbox or radio button is "on". For types "submit" and "reset", VALUE can be used to specify the label for the pushbutton. CHECKED specifies that this checkbox or radio button is checked by default; this is only appropriate for checkboxes and radio buttons. SIZE is the physical size of the input field in characters; this is only appropriate for text entry fields and password entry fields. If this is not present, the default is 20. Multiline text entry fields can be specified as SIZE=width,height; e.g. SIZE=60,12. Note: the SIZE attribute should not be used to specify multiline text entry fields now that the TEXTAREA tag is available. MAXLENGTH is the maximum number of characters that are accepted as input; this is only appropriate for text entry fields and password entry fields (and only for single-line text entry fields at that). If this is not present, the default will be unlimited. The text entry field is assumed to scroll appropriately if MAXLENGTH is greater than SIZE.

42 Input: type attribute (submits data) (resets to defaults) (user defined) – (asterisks) (toggle) (toggle-only one) (isn’t displayed)

43 Input: type attribute Default is “text”

44 Other Input Attributes name value checked size maxlength

45 Submit Button When a user clicks on a submit button the browser submits the contents of all other fields to a web server using the method and action attributes. May have multiple submit buttons on a page (with different values). Default value is “Submit Query”

46 Reset Button When user presses the reset the entire form is cleared. The displays are reset to the initial values which have been saved.

47 Button “push button” User defined Discussed with JavaScript

48 Text Creates a text box into which user types. When the form contains only a single text entry field, the form can be submitted by pressing return in the text box as well as by pressing the Submit Query button. E.g. Google gives you this hint. Their submit button has the value “Google Search”.

49 Text <input type=“text” name=“pizza” size=“10” maxlength=“20” value=“pepperoni”>

50 Text please enter your name: please enter your age:

51 Use Table to Format Form your name: your age:

52 Password Text appears as asterisks on screen. Why?

53 Checkbox Radio A/C Global Positioning System Leather seats

54 Checkbox “extras” is the name of the checkbox, and links the group of checkboxes. “value” is the text that will be sent if the box has been checked. Any number of boxes may be selected. They may be initially selected or deselected.

55 Radio Buttons Jack Queen King Ace

56 Radio Buttons “card” is the name of the group and links the group of radio buttons. Every button in the group must have the same name.) “value” is the text that will be sent to the server if that button is chosen. Only one button can be selected—they are mutually exclusive.

57 Select Menu Dropdown list Scrolling list

58 Select SELECT has both opening and closing tags. Inside SELECT, only a sequence of OPTION tags -- each followed by an arbitrary amount of plain text (no HTML markup) -- is allowed. SELECTED attribute specifies that this option is selected by default. If the SELECT allows multiple selections (via the MULTIPLE attribute), multiple options can be specified as SELECTED.

59 Select Pick option. First option. Second option.

60 Attributes for Select NAME is the symbolic name for this SELECT element. This must be present, as it is used when putting together the query string for the submitted form. SIZE: if SIZE is 1 or if the SIZE attribute is missing, by default the SELECT will be represented as a Motif option menu. If SIZE is 2 or more, the SELECT will be represented as a Motif scrolled list; the value of SIZE then determines how many items will be visible.

61 Attributes for Select MULTIPLE, if present, specifies that the SELECT should allow multiple selections (n of many behavior). The presence of MULTIPLE forces the SELECT to be represented as a Motif scrolled list, regardless of the value of SIZE.

62 Select Color Red Green Yellow Blue

63 Textarea The textarea tag creates an area where the user can submit multiple lines of text. … attributes: –name –Rows (default is 2) –Cols (width in characters) (default is 20)

64 Textarea Has automatic scrollbar; any amount of text can be entered. May have default contents : Default contents go here. Newlines are respected. There will be a newline both before and after "Default contents go here."

65 Example please enter your address :

66 Hidden Nothing is displayed by the browser. Name and value are sent when submitted stores info between client/server exchanges that would otherwise be lost Not really hidden. Can see it in the source.

67 Examples http://archive.ncsa.uiuc.edu/SDG/Software /Mosaic/Docs/fill-out-forms/example-1.htmlhttp://archive.ncsa.uiuc.edu/SDG/Software /Mosaic/Docs/fill-out-forms/example-1.html Can you code these? His source is a nightmare. See form group example See menus.html ?

68 Homework

69 Summary Tables (rows of data cells) to arrange elements on a webpage Forms to collect user data and send it to server. –Attributes :Method, Action –Input elements – we’ve seen (what are they?): Buttons (3) Texts (2) Toggles (2) Hidden (1) –Textarea –Select


Download ppt "HTML: Tables and Forms. Objectives Use tables to structure a webpage Use forms to collect user input –Method:Get, Post –Input –Select –Textarea."

Similar presentations


Ads by Google