Week Two HTML Html5 XHTML
Week Two HTML Html5 XHTML
WEEK TWO
HTML/XHTML/HTML5
HYPER-TEXT MARKUP LANGUAGE
(HTML)
• HYPER-TEXT MARKUP LANGUAGE (HTML) - IS A KNOWN AS A
MARKUP LANGUAGE.
• MEANING IT IS A WAY OF ANNOTATING A DOCUMENT IN SUCH A
WAY AS TO MAKE THE ANNOTATIONS DISTINCT FROM THE TEXT
BEING ANNOTATED.
• ALLOWS THE USER TO CONTROL HOW TEXT AND VISUAL
ELEMENTS WILL BE LAID OUT AND DISPLAYED.
• IN ITS SIMPLEST FORM MARKUP IS A WAY TO INDICATE
INFORMATION REGARDING CONTENT THAT IS DISTINCT FROM
THE CONTENT ITSELF.
• IS DONE VIA TAGS/ELEMENTS.
• CAN ALSO ENCODE INFORMATION ON HOW TO DISPLAY THE
CONTENT FOR THE END USER.
EXTENSIBLE HYPER-TEXT MARKUP LANGUAGE
(XHTML)
• XHTML is a version of HTML that uses stricter XML (eXtensible Markup
Language) syntax rules.
• As the web evolved, web browsers evolved into lenient and permissive
programs. allowing for sloppy HTML (missing or malformed tags and
other syntax errors).
• Created issues with how various browsers would handle these errors.
Sibling
<strong> <p>
<span>
Ancest
or
HTML5 –SEMANTIC HTML
• When coding an absolute URL you need to code the complete URL which
includes the domain name, any subdirectories and the file name. For
example: web.njit.edu/myfirstpage.html
• When coding a relative URL remember that it is based on the current
folder which is the folder that contains the current page.
•There are two types of relative URLs:
• A root-relative path which is a relative to the root folder of the website. It
will always start with a forward slash and then goes down one subfolder by
indicating the subfolder name followed by a slash. This pattern continues
until you reach the file needed. For example: /images/logo.jpg refers to
root/images/logo.jpg
• A document-relative path is a relative to the folder the current document is
in. To go down one subfolder, you code the subfolder followed by a slash. This
pattern continues until you reach the file needed. For example:
books/images/logo.jpg refers to the root/books/images/logo.jpg You can also
go up in a document-relative path. To go up one level from the current folder
you code two periods and a slash. This pattern continues until you reach the
file needed. For example: ../index.html refers to root/index.html.
URL – RELATIVE REFERENCING
• Relative referencing is a way of accessing a file via a path.
• When referencing a page or resource from an external site, a full
absolute reference (path) is required (meaning the complete URL).
• If referencing a resource residing on the same server, a briefer
relative referencing can be used.
• If all the resources for the site reside in the same directory (folder) you can
reference those resources simply via the file name.
• If all resources are not found in a single directory a relative pathname is
required along with the filename. This pathname tells the browser where to
locate the required file on the server.
<table
>
<tr Student Name Major Advisor
> <th> <th> <th>
<tr>
John Smith. Data Science Jones
<tr <td>
<td> <td>
>
<tr
>
Emma Warren Electrical Engineering Winters
<tr <td> <td> <td>
>
Henry Morris Biology Waverly
<td> <td> <td>
<table style="width:25%">
<tr>
<th>Name</th>
<td>Jane</td>
</tr> Row “Phone” Spans
<tr> 2 rows
<th rowspan="2">Phone</th>
<td>973-555-5500</td>
</tr>
<tr>
<td>973-555-5505</td>
</tr>
</table>
TABLES
<option>Ireland</option>
<option>Italy</option>
<option>Spain</option>
</select>
</p>
<input type="submit"/>
Form
</form> generated
FORMS
• A Deeper Dive:
• Defined by using the <form> element.
• Is a container for other elements that represent various input
elements as well as plain text and almost any other HTML
element.
• Requires some type of server sided resource to process the
user’s input.
• The process is as follows:
• The user makes a request of the web server via an HTTP
request.
• The browser returns a document that contains the form.
• The user fills out the form and hits submit.
• The user’s form data is sent to the server.
FORMS
• A visual of process:
UNDERSTANDING FORMS
Typeoffood=Pasta&country=Italy
name=value pair
Attribu Description
te
type The type of the control/input element. For example, text, button,
checkbox.
id A unique id that can be referred to by the client-side code.
name A name that can be referred to by the client-side or server-side
code.
disable A Boolean attribute that disables and grays out the control. The
d control will not be able to receive the focus, the user will not be
able to tab to it and the value is not submitted by the form.
readonl A Boolean attribute that means a user cannot change the
y control’s/element’s value. The control can receive the focus, the
user can tab to it and the value is submitted by the form .
COMMONLY USED FORM ELEMENTS
• HTML has several different ways for a user to select input from a
list of options:
• <select> element - creates a multiline box for selecting one or
more items.
• radio buttons – allows for the selection of a single item
(default) from a small list of choices (allows all the choices to
be visible).
• checkboxes – allows for the selection of one or more
checkbox(es).
<SELECT> ELEMENT
• Creates drop-down menu options via the <option> element.
• An id attribute is required to associate the drop-down list with a label.
• The name attribute is needed to reference the form data after the form is
submitted. If omitted, no data from the drop-down list will be submitted by
the form.
• The <option> element defines valid options which can be hidden a in a
drop-down menu or be multiple rows of the list that are visible. If there are
more options than can be displayed a scroll is added to the drop-down list.
• Can also group option items together by using the <optgroup> element.
• The <option> element attributes:
• selected attribute - allows a specific item in the list of values to be
chosen as a default value. If not used the default value will be the first
option in the drop-down menu.
• value attribute - indicates what value will be sent back to the server in
the query string when the option is selected.
<SELECT> AND <OPTION> ELEMENTS
• An example of a drop-down menu via the <select> and <option>
elements:
Produced by the <select>
element
<label>Choose a Course</label>
<select id = "course" name = "course">
<option>IT114</option>
<option>IT202</option>
<option>IT490</option>
Produced by the <option>
</select> element
NOTE: the code above uses the label element to create the text
Choose a Course. Making the text an option allows it to be shown
as the first option in the dropdown-menu.
<SELECT> AND <OPTION> ELEMENTS
WITH SIZE ATTRIBUTE
• An example of a drop-down menu via the <select> and <option>
elements and size attribute:
• size attribute specifies the number of visible options in a drop-
down list.
• if its value is greater than 1, but lower than the total number of
options in the list, the browser will add a scroll bar to indicating
more options to view.
Produced by the size attribute
<label>Choose a Course</label>
<select id = "course" name = "course" size = "3">
<option>IT114</option>
<option>IT202</option>
<option>IT490</option>
</select>
<SELECT> <OPTION> AND
<OPTGROUP>ELEMENTS
• An example of a drop-down menu via the <select> and <option> and
<optgroup> elements:
<label>Choose a Course</label>
<select id = "course" name = "course"> Note: that IT202 is
displayed even
<option value = "114"> IT114 </option> though it is the
<option value = "202" selected> IT202 </option>
second item in the
list
<option value = "490" > IT490 </option>
</select>
<SELECT> AND <OPTION> ELEMENTS
AND MULTIPLE ATTRIBUTE
• An example of a drop-down menu via the <select> and <option>
elements and the multiple attribute:
• The multiple attribute allows for the selection of more than one item
from a drop-down menu.
Produced by multiple attribute
<select id = "course" name = "course " multiple>
<option value = "114"> IT114 </option>
<option value = "202"> IT202 </option>
<option value = "490" > IT490 </option> Note: more than one
option item is
</select> allowed to be
selected
<SELECT> ELEMENT WITH VALUE
ATTRIBUTE
• An example of a drop-down menu via the <select> and <option>
elements and the value attribute:
<label>Course</label> <label>Course</label>
<select id = "course" name = "course"> <select id = "course"
name = "course">
<option>Choose a course</option> <option>Choose a
course</option>
<option> IT114</option> <option> = value = "114"
> IT114 </option>
<option> IT202</option> <option> = value = "202"
> IT202 </option>
Query String
Query
<option> String
IT490</option> <option> = value = "490"
Created
Created
> IT490 when IT202
</option> When IT202 is
is selected
</select>
?course=IT202 </select>selected
?course=202
RADIO BUTTONS
• Buttons allow for the selection of a single item from a small list of choices as they
are normally presented in “radio groups” which describe a set of related options.
• Use when you want all the choices to be visible.
• Created via the <input> element’s type attribute:
• <input type = "button"/>
• Radio button attributes:
• name attribute – makes buttons mutually exclusively (meaning only one can be
chosen at a time). This is done by having the same value associated with the
name attribute for each button. This can be overwritten by giving each individual
button a unique value associated with the name attribute.
• checked attribute is used to indicate the default value for a button.
• value attribute - indicates what value will be sent back to the server in the query
string when the option is selected. Note: the value attribute is different for each
button which allows the client-side or server-side server code to retrieve the
value of the button selected.
•
RADIO BUTTONS
An example of buttons created via the <input> element and type
and value attributes:
<label>Travel Destinations?</label>
<br>
<br>
<input type = "radio" name = "destination" value =
"Dublin"/>Dublin, Ireland<br>
<input type = "radio" name = "destination" value =
"Rome"/>Rome, Italy<br>
<input type = "radio" name = "destination" value = "Paris"/>Paris,
France<br>
RADIO BUTTONS AND CHECKED ATTRIBUTE
• An example of buttons created via the <input> element and
type, value and checked attributes:
<label>Travel Destinations?</label>
<br>
<br>
<input type = "radio" name = "destination" value = "Dublin"
checked/>Dublin, Ireland<br>
<input type = "radio" name = "destination" value =
"Rome"/>Rome, Italy<br>
<input type = "radio" name = "destination" value = "Paris"/>Paris,
France<br>
RADIO BUTTONS
• As stated previously HTML allows you to overwrite the default of
allowing a selection of a single radio button.
• The code below demonstrates this how this can be accomplished.
<label>Travel Destinations?</label>
<br>
<br>
<input type = "radio" name = "destination1" value = "Dublin
"/>Dublin, Ireland<br>
<input type = "radio" name = "destination2" value =
"Rome"/>Rome, Italy<br>
<input type = "radio" name = "destination3" value =
"Paris"/>Paris, France<br>
CHECK BOXES
<label>Travel Destinations?</label>
<br>
<br>
<input type = "checkbox" name = "destination" value =
"Dublin"/>Dublin, Ireland<br>
<input type = "checkbox" name = "destination" value =
"Rome"/>Rome, Italy<br>
<input type = "checkbox" name = "destination" value =
"Paris"/>Paris, France<br>
CHECK BOXES AND CHECKED ATTRIBUTE
• An example of check box created via the <input> element and
type, value and checked attributes:
<label>Travel Destinations?</label>
<br>
<br>
<input type = "checkbox" name = "destination" value = "Dublin"
checked/>Dublin, Ireland<br>
<input type = "checkbox" name = "destination" value = "Rome"/>Rome,
Italy<br>
Note name
<input type = "checkbox" that the checked attribute
= "destination" valuedoes not
= "Paris"/>Paris,
consist of an attribute name = value pair.
France<br>
This is because this attribute is a Boolean
attribute meaning it can have two values on
or off. When turned on the related
checkbox/radio buttons is checked when the
page is rendered.
CHECK BOXES AND CHECKED ATTRIBUTE
• An example of check box with multiple checkboxes checked.
<label>Travel Destinations?</label>
<br>
<br>
<input type = "checkbox" name = "destination" value = "Dublin"/>Dublin,
Ireland<br>
<input type = "checkbox" name = "destination" value = "Rome"/>Rome,
Italy<br>
<input type = "checkbox" name = "destination" value = "Paris"/>Paris,
France<br>
RADIO BUTTONS AND CHECK BOXES
• For both radio buttons and checkboxes can use the <label>
element to help with accessibility of these controls. Instead of
having to click on a small button or box this option allows a user
to click on the given text in the <label> element for a radio
button or checkbox when choosing an option. This is
accomplished by setting the for attribute of the <label> element
to the id attribute for the radio button or checkbox.
BUTTON CONTROLS
• HTML defines several different types of buttons that can be created via the <input> element:
• <input type = "submit"/> element- creates a button that submits form data to a server for
processing automatically without using client-side code. The default value for text in
button is ”Submit”. Can customize the text by using the value attribute.
• <input type = "reset"/> element - creates a button that clears data already entered and
resets them to their default values. The default value for text in button is ”Reset”. Can
customize the text by using the value attribute.
• <input type = "button"/> element - creates a custom button that may require JavaScript for
it to perform any function since when clicked client-side code is usually run. The default
value for text in button is ”Button”. Can customize the text by using the value attribute.
• <input type = "image"/> element - creates a custom button that uses an image as its
display. It works just like the submit but displays an image rather than text. To specify the
URL for the image, use the scr attribute. To specify text if the image cannot be displayed
use the alt attribute. To set the size of the button use the height and width attributes.
• <button> element - creates a custom button.
• differs from the <input type = "button"/> in that it what appears in the button can be
completely customized by the developer.
• For example: the button may include both text and image or skip server-side
processing entirely by using hyperlinks. This button can be turned into a submit
button by using the type = "submit" attribute.
BUTTON CONTROL
FORM CONTROLS
• HTML has two special purpose form controls:
• <input type = "hidden"/> - used to include data that cannot be seen or
modified when a form is submitted. The field is not displayed in the browser
and therefore the user cannot enter data into it. Instead, the value is set via
the value attribute.
• <input type = "file"/> - used to upload a file from a client to a server. When
using this control, the method attribute must be POST and you must
include the enctype attribute.
• HTML5 introduced two new controls for the input of numeric values. Allowing for
validation of numbers.
• <input type = "number"/> element
• <input type = "range"/> element
• Both provide a means to input numeric values that eliminate the need for
client-side numeric validation.
DATE AND TIME CONTROLS
• date - creates a general date input control. The format for the
date is yyyy-mm-dd <input type = "date"/>
• time - creates a time input control. The format for the time is
HH:MM:SS <input type = "time"/>
• datetime - creates a control in which the user can enter a date
and time. <input type = "datetime"/>
• datetime-local - creates a control to enter date and time without
entering a specified time zone. <input type = "datetime-local"/>
• month - creates a control to enter a month in a year. The format
is yyyy-mm <input type = "month"/>
• week - creates a control to specify a week in a year.
<input type = "week"/>
COMMENTS
• It is important to remember that you may create a piece of code, but you
may not always be the individual maintaining that piece of code and
therefore comments are an essential part of coding. A common use for
comments is to describe/explain portions of code. They can also be used
to comment out piece of code temporarily when for testing or debugging
purposes. In HTML we denote a comment with the following characters:
•Find the document you are looking to test and double click on the file name.
• The file will then open in your browser. This will allow you to check the content and
appearance of your page.
• It is also important to test your page(s) in various browsers to ensure the page(s) renders as
expected.
• If an error occurs in the rendering, then you will need to debug your code (find the issues
and fix them).
•Some of the issues you may encounter may be trivial while others may be more significant.
•Finding these errors can be done via your browser’s Web Development Tools.
• You can find how to use the tools by reading my posting under the Week 0 module called
Web Development Tools.