CHAPTER 2: XHTML, CSS AND JAVASCRIPT (XHTML)
I. XHTML (EXTENSIBLE HYPERTEXT MARKUP LANGUAGE )
As HTML has progressed and evolved over time, new versions of the language have been released to introduce the new features and deprecate the old. The very first version of HTML, 1.0, was published in 1993. It was further refined and extended with HTML 2.0 in 1995, followed closely by HTML 3.0 in 1996. Version 4.0 was published in 1997, and a few minor (but significant) changes were released in 1999 as HTML 4.01. This was to be the final, complete specification for the HTML language. A new kid called eXtensible HTML, or XHTML, joined the class in 2000, and it was praised as the wave of the future. XHTML is a reformulation of HTML following the more stringent rules of eXtensible Markup Language (XML).
Web pages are created with XHTML. An XHTML document start with two lines
Followed by:
The tags defines the head section. This section contains the1. XHTML TAG SYNTAX
XHTML tags begin with a left angle bracket (<) followed by the name of the tag and end with a right angle bracket (>). All tags are paired into a beginning tag and an ending tag, such as and . The ending tag looks just like the beginning tag except that a forward slash (/) precedes the tag name within the brackets. You typically place the tag content between the beginning and ending tags. The following table shows commonly used XHTML tags.
Feature Example tag Heading
Line break
or
List item
Bold text Paragraph 2. CONTENT TAGS
After creating the basic structure of an HTML document, you can add content to the body of the document. While there are many tags for altering the appearance of content, the basic elements are headings, paragraphs, and lists.
2.1 HEADINGS
Headings are basically used to mark the beginning of a new paragraph. Headings range in size from one to six, one being the largest. A level one heading, for example, is marked by the
and
tags. Headings are displayed in larger and bolder fonts than normal body text. The syntax of the heading tag is:The following is an example that uses the
HEADING 1
HEADING 2
HEADING 3
HEADING 4
HEADING 5
HEADING 6
2.2 PARAGRAPHS AND LINE BREAK
A paragraph tag indicates where a new paragraph begins. You begin a paragraph with the opening paragraph tag
and close the paragraph with the closing paragraph tag
. Word wrapping is determined by the size of the browser window. Here is a sample HTML code that uses the paragraph tag:
Here is the new paragraph.
You can also control line length and line breaks by using the
tag, which indicates a line break. It is important to note that a browser ignores white spaces. Therefore, the following three code segments:
Hello There
Hello There
andHello There
Will produce the same output.2.3 LISTS
HTML supports several elements for creating different types of lists. There are three kinds of list tags in HTML: - Ordered lists - Unordered lists - Definition lists
2.3.1 ORDERED LISTS
You use the
THOU CHAMROEUN Page 2
- XHTML
- CSS
- JavaScript
- or ASP
2.3.2 UNORDERED LISTS
You use the
- XHTML
- CSS
- JavaScript
- or ASP
2.3.3 DEFINITION LISTS
A definition list is similar to a definition in a dictionary. You can use XHTML tags to create definition lists. In a definition list, each list item has two parts, a
- XHTML
- tell what the content is
- CSS
- tell how to display the content
2.4 HYPERLINK TAGS
A hyperlink is a connection from a Web page to another page or a different location on the same page. To add a hyperlink to a Web page, you need the URL of the Web site to which you want to link. The anchor tag is used for setting a hyperlink in a Web page. The syntax for a hyperlink is:
Where Destination_URL is the URL of the Web site you want the hyperlink to connect to, and text or graphic is what the user will click to view the specified Web site.
2.4.1 TYPES OF HYPERLINKS
The following table lists the types of hyperlinks you can create and gives examples of the HTML syntax.
Hyperlink type Description Syntax URL A hyperlink to another Web page http://xxx/xxx/xxx/dir/file.htm Non-HTML document A hyperlink to another type of document, such as a file:\\path\dir\filename Microsoft Word document, a Microsoft Excel workbook, or an image Bookmark A hyperlink to a named area defined within a Web page. Mypage.htm#bookmarkname E-mail A hyperlink to an e-mail address. mailto:[email protected] m Newsgroup A hyperlink to a newsgroup in a Usenet site. news:xxx.xxx.xxx
There are two types of hyperlinks that you can define in a Web page: - Relative links - Absolute links
2.4.1.1 RELATIVE LINKS
Relative links describe the destination relative to the location of the Web page containing the link. Relative links are so called because you specify the path to get from the current page to the destination page. For example, a relative link to a document in the same folder as the current Web page would be MyDocument.htm.
You can also specify a file in another folder on the same server by specifying the relative path from the current document to the linked document as shown in the following example:
In addition, you can specify a file in another folder on the same server by specifying the path from the root directory of the current page to the linked document.
2.4.1.2 ABSOLUTE LINKS
An absolute link is used to link documents that are not part of the same site. An absolute link provides a complete address for a hyperlink. For example, an absolute link to a document MyDocument.htm is: "C:\My Web Documents\MyDocument.htm"
You can use an absolute link to define a link to a Web page on another Internet server.
2.4.1.3 RELATIVE VS. ABSOLUTE
The advantage of relative links is that if you move files as a group to another location, the relative link addresses remain unchanged. However, you must use an absolute link for files that are not in the server computer or on the same Internet server.
THOU CHAMROEUN Page 4
2.4.1.4 BOOKMARK
When a Web page is more than one or two screens in length, you can add bookmarks within the page and create hyperlinks to the bookmarks such that the users can jump directly to specific sections of the page. You can use bookmarks to create a simple table of contents for a long Web page. To define a bookmark, you use the tag and set the name attribute. The following example defines a bookmark named bookmark1:
To go the defined a bookmark, use the tag and specify the page to link followed by a pound sign (#) and the bookmark name. The following example creates a hyperlink to the bookmark named bookmark1 in the page MyDoc.htm.
3. ADDING IMAGES TO A WEB PAGE
You can enhance the appearance of a Web page by adding images. Images can add information to a Web page and make it more appealing and interesting for users. Browsers can display image files in a document if they are in either .GIF (Graphics Interchange Format) or .JPG format. Different formats compress images using different algorithms. For example, an image will have a different file size depending on whether it is saved as a .gif or a .jpg file. Because the time it takes to download an image is directly related to the size of the file, you will want to use the format that results in the smallest file size.
The tag is used to add images to Web pages. The syntax for this tag is:
The tag instructs the browser to display the image at this location in the document. The src attribute tells the browser the file name of the image to display. In this case, a file named filename.gif is in the same directory as the HTML document in which the image is displayed.
3.1 CREATING HYPERLINKED IMAGES
You may want to have an image that is linked, so that clicking the image will open another page. This is rather simple. You just need to place the IMG tag within the A HREF tags as follows:
4. CREATING TABLES
Tables have many uses in Web pages. They are used in a conventional manner to display information in a tabular format.
You can present information in a more structured manner to users by using tables.
Class Name Room No. Lab Room No. M2 102A 212 M4 406 212 A1 102A 205 E2 102B 212
For example, the Web page above contains a table that shows airline information in a structured manner. You can see that next to each airline.Blue Sky Airline, Blue Yonder Airways, and, Vigor Airline.the departure and destination places and the time of departure are listed.
THOU CHAMROEUN Page 5
Each row in a table is created by using the
Columns are created by using the
Every cell in the table must have some content, or many browsers will not render the cell. If you want a cell to appear blank, place a non-breaking space in it. For example:
5. CREATING FORMS USING HTML
A form allows users to send information to the server. Typical uses for a form include: - Asking users to provide information during an online purchase, such as name, address, and credit card information. - Allowing users to select options to retrieve specific information to be displayed on a subsequent page. For example, allowing users to select the city that they want to see the weather for. - Allowing users to submit comments or provide other feedback.
5.1 THE
tags to create a form. You can place other XHTML elements within the form tags to specify the exact contents of the form. The following code defines a form that contains several fields, a submit button, and a reset button. When the user submits the form, the contents are sent to formProcessor.asp, which will actually process the form.
THOU CHAMROEUN Page 6
You can determine the behaviour of a form by setting attributes for the form. The
THOU CHAMROEUN Page 7
5.3 FORM CONTROLS
A form can contain the following type of controls: - Text box - Password - Text area - Push button - Radio button - Drop-down menu - Check box - Hidden
5.3.1 USING TEXT CONTROLS
There are three types of text boxes as listed in the following table.
Text box type Syntax Single-line Password Scrolling
The following example part of code defines a single-line text box, a password, and a scrolling text box:
Full Name:
Password:
Comments:
In the above example, size specifies the length of the text box. Rows and Cols specify the number of rows and columns the text area will span.
5.3.2 USING PUSH BUTTONS
There are three types of push buttons: Normal, Reset, and Submit. To use XHTML tags to add these buttons, you use the tag and set the type attribute to the type of button you are creating. The value attribute is set to the text that should appear as the caption of the button. The following table lists the syntax for each type of button.
Button type Syntax Submit Reset Normal
A Submit button will cause the contents of the form to be sent to the server. The following example code defines a Submit button: A Reset button will clear the contents of the fields on the form. The following example code defines a Reset button:
You can also define a Normal button. This button does nothing unless you specifically write client-side script for the button, to handle some processing. You will learn more about client-side scripting later. The following example code defines a Normal button named btnclickme:
5.3.3 USING RADIO BUTTONS AND CHECK BOXES
5.3.3.1 RADIO BUTTONS
Radio buttons are typically used in a form, when the user has to choose only one option from a set of options. To add a radio button control to a form, use the tag and set the type attribute to radio. Use a separate tag for each radio button that you create. To create a group of radio buttons, assign the same name attribute to all the radio buttons in the group. To specify which radio button option is selected by default when a user views the THOU CHAMROEUN Page 8 web page, add the checked =”checked” attribute to the tag. The following part of code displays a radio button group that provides three options: Yes, No, and Maybe. The Yes option is selected by default
Are you aware of the interactive web page?
5.3.3.2 CHECK BOXES
Check boxes are typically used when the user can choose more than one option from a given set of options. To add a check box control to a form, use the tag and set the type attribute to checked. To make the check box appear as selected when the user views the page, add the checked=”checked” attribute to the tag. To add descriptive text to the check box, include the text after the tag. The following example code displays two check boxes; the first box is checked by default:
Are you able to create :
5.3.4 USING DROP-DOWN MENUS
To create a drop-down menu in your form, use the
If you want the user to be able to select more than one item from the drop-down menu, add the multiple="multiple" attribute to the
Tip! Use drop-down menus instead of radio buttons or check boxes to gain space in your Web pages
5.3.5 USING HIDDEN CONTROLS
Sometimes you may need to use hidden controls in your form, to store some internal information, which is not to be displayed to the user. To add a hidden control to a form, you use the tag and set the type attribute to hidden. Set the value attribute to the text that you want to be sent with the hidden control. The following example code creates a hidden control named hdnName. When the user submits the form, the text for the value attribute is sent to the server. Hidden controls are often used to store state information on the client.
THOU CHAMROEUN Page 9
5.4 FORMATTING FORMS
Forms can be formatted to improve user interaction. To format a form, you can add HTML tags or change attributes of the existing tags.
5.4 .1 SETTING THE TAB ORDER
To set the tab order for the controls on a form, set the TABINDEX attribute for each control as shown in the following example code.
5.4 .2 ADDING LABELS
If you add a label to a control, the user can select the control by clicking either the label or the control. To add a label, first set the id attribute of the control. You can use the value of the id attribute to refer to a control from another control. Next, add the
5.4 .3 ADDING ACCESS KEYS
To create an access key for a control, set the accesskey attribute in the
THOU CHAMROEUN Page 10