Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

HTML 4_01 Weekend Crash Course - G. Perry

.pdf
Скачиваний:
34
Добавлен:
24.05.2014
Размер:
6.32 Mб
Скачать

Session 27—Adding Other Special Elements to the Web Site

367

<!-- Second cell in Movie description row -->

<td width=1113 height=98 bgcolor=#FFFFFF valign=top colspan=2> <hr>

<p align=left>

<font color=#000000 face=Arial>

Capsule: A vacationing family learns that love comes only

from

<br>  commitment, responsibility, and concern. </font></P>

</td>

<tr> <!-- End of the first two rows of content -->

<!-- Continue the second row... -->

<td width=170 height=106 bgcolor=#FFFFFF valign=top align=right> <p align=center>

<a href=”http://www.xyzMovies.com/STMoon.htm/”> <font face=Arial size=3 color=#009900>

Movie’s Web site </a></p>

<p align=center>Barkley Family Rating:<br> </font>

<font face=”Arial” color=#009900 size=4> 3.5 of 5 Stars</font>

</td>

<!-- The right cell of the second row -->

<td width=1113 height=106 bgcolor=#FFFFFF valign=top colspan=2> <p align=left>

<font face=Arial>  Mom: 4 - <i>Finally, a realistic solution for family troubles!</i><br>

  Dad: 3 -

<i>Slow in places, overall good, needs more action.</i><br>   Rachel: 4 - <i>I liked it!</i><br>

  Annie: 3 - <i>I didn’t see any horses...

</i></font></P>

<p>

<font color=#000000 face=Arial>

Friends’ compiled rating: 3.25 Stars - Add yours below!

Session

Sunday—VI Part

27

Afternoon

Continued

368

Sunday Afternoon

Listing 27-1

Continued

</font>

</td>

</tr>

<tr>

<!-- The bottom row of the content page begins here --> <td width=”170” height=290 bgcolor=white valign=top

align=right>

<hr>

</td>

<td width=494 height=290 bgcolor=white valign=top> <hr>

</td>

<td width=397 height=290 bgcolor=white valign=top>  

</td>

</tr>

</table>

<!--------------------------

>

<!-- Any footer goes here --

>

<!--------------------------

>

</body>

 

</html>

 

Adding the Form to the Favorite Movies Page

The special part of the movie page — the rating form — occurs in the table’s third row. Figure 27-2 shows the form that appears at the bottom of the page. Again, this entire Web page will not fit on most user monitors, but that’s okay. The page is not the home page, and the user won’t mind scrolling.

Session 27—Adding Other Special Elements to the Web Site

369

Figure 27-2

The bottom of the movie page holds a form the user can submit.

The Barkleys are keeping the form simple. They want results e-mailed to them. Notice that the form contains these controls:

A description in the left cell

Five radio buttons for the star-rating system

A multiline text box

A Submit button that triggers e-mailing the form’s contents

A Reset button that resets the user’s entries

 

The Barkleys do not use check boxes for the star-rating system.

 

If the form contained check boxes, users would be able to select

Note

multiple ratings for the same movies. The radio buttons keep the

choices down to one.

In Session 14, you learned how to add form elements to your page. Forms are relatively simple to add. The Barkleys could have had the form answers submitted to the Web host, via a CGI script. E-mailing of the answers, however, is a much

Session

Sunday—VI Part

27

Afternoon

370

Sunday Afternoon

simpler solution. It brings the form data to the Barkleys on an individual basis so that each e-mail message from the form brings a new set of form results.

Listing 27-2 shows the rest of the code that completes the page and displays the form. The HTML code for the form is simple, but it does the job.

Listing 27-2

Creating the form

<td width=170 height=290 bgcolor=white valign=top align=right> <hr>

<p align=center><font color=#000000 face=”Arial”>Submit this form and we’ll update our Friends’ compiled rating</font>

</td>

<td width=494 height=290 bgcolor=white valign=top> <hr>

<form method=post name=”MovieSTM” action=”mailto:Barkleys@email.mn.net”>

<p align=center>

<i><font face=Arial size=4 color=#009900> <b>Saving the Moon</b>

</font><br>

</i><font color=#000000 face=Arial> Your Rating:<br>

</font>         *<input type=radio name=R1 value=V1> <br>      

**<input type=radio name=R1 value=V2> <br>    

***<input type=radio name=R1 value=V3> <br>  

****<input type=radio name=R1 value=V4> <br> 

<!-- Last button is selected due to ‘checked’ option -->

*****<input type=radio name=R1 value=V5 checked></p> <p align=left> <font color=#000000 face=Arial> Enter any comments: </font>

<textarea rows=2 name=S1 cols=20> </textarea>

<input type=submit value=Submit name=B1>

Session 27—Adding Other Special Elements to the Web Site

371

<input type=reset value=Reset name=B2> </p>

</form>

<p> 

</td>

<td width=397 height=290 bgcolor=white valign=top>  

</td>

</tr>

</table>

<!--------------------------

>

<!-- Any footer goes here --

>

<!--------------------------

>

</body>

 

</html>

 

When the form contents are mailed to the Barkley family, the V1 through V5 variables contain 1 or 0 based on the user’s selection (1 if the user checks the radio button, 0 if the button is unchecked). By default, the five-star radio button is selected when the form first appears on the screen; this is true because of the checked option in the fifth button’s <input type=radio> attribute.

Creating the Image Map for the Family Travels Page

An image map is a graphic image that contains multiple links. It forms a backdrop for the hyperlinks forming the image map. Depending on where the user clicks, the image map takes the user to a different location. You should load the graphic image that you’ll use as the image map into your graphics program and note the pixel coordinates (both width and height) for the entire image and the coordinates of the areas you want to use as hot spots for the links.

An image map’s links can fall into the following kinds of hot-spot areas:

A rectangle defined by the upper-left and the bottom-right coordinate pairs

A triangle defined by three coordinate pairs, one at each of the three angles

A circle defined by two coordinate pairs: the center and the right-edge coordinate point

Session

Sunday—VI Part

27

Afternoon

372

Sunday Afternoon

Note

Two pixel measurements always define a pair of coordinate points: the starting pixel row width and the starting pixel column height of the point. Therefore, a coordinate pair of 130, 245 specifies a point exactly 130 pixels to the right and 245 pixels down from the upper-left corner of an image. The upper-left corner is considered to be the starting point.

The Barkleys’ recent vacation spots will serve as hot spots on the map. They have visited the following places in the past three years, and they want to share pictures and memories of those places on their site’s Family Travels page:

San Diego, California

New York City

Miami, Florida

Toronto, Canada

The Family Travels page contains the usual header and navigation bar used for the other primary pages of the site. The body of the page contains only a map of the United States, as shown in Figure 27-3.

Although only enough time exists to cover the use of the image map briefly, your HTML education would not be complete without an example. Given that the vacation spots are so far apart, the Barkleys decide to use simple rectangular hot-spot areas to mark their four vacation locations. The image is only 285 x 295 pixels wide.

When you use an image map, you place the image on the Web page as usual using the <img> tag. Inside the <img> tag, use the usemap= attribute to name the map in case the page has, or will have, multiple image maps. Either immediately following the <img> tag or last in the HTML code, you should specify the coordinate points for every hot spot in the image.

Consider the following section of an HTML file that uses an image map:

<img border=0 src=”US.gif” usemap=”#states” width=285 height=295> <map name=”states”>

<area shape=rect coords=”26, 167, 56, 197” href=”http://www.BarkleyFamilyPage.com/LA.htm”>

<!-- More coordinates and link references would follow --> </map>

Session 27—Adding Other Special Elements to the Web Site

373

Figure 27-3

The map provides a backdrop for hyperlinks forming an image map.

The image is named US.gif, and the image contains mapped coordinates named “states”. The <area> tag tells the browser the coordinates that define the rectangle (26, 167, 56, and 197, in this case); when the user clicks anywhere within that coordinate range, the hyperlink takes over. You specify as many coordinates and links as the image requires, and then you terminate the coordinates with a </map> tag.

 

A triangular hot spot would require six values, making a total

 

of three coordinate pairs. A circle requires only four values,

Note

making a total of two coordinate pairs (the circle’s center

and its right edge).

The Barkleys use code just like this to map the four hot spots onto their map named, not coincidentally, US.gif. The code in Listing 27-3 shows the entire image mapping for the states. The image map requires very little HTML code. (This crash course does not create any of the image map’s linked pages.)

Session

Sunday—VI Part

27

Afternoon

374

Sunday Afternoon

Listing 27-3

Creating the entire image map with the four hot spots

<!-- Image map comes next for travels -->

<td width=1864 height=290 bgcolor=#FFFFFF valign=top> <font face=Arial size=4>

These are the areas of our travel pages. <br>  Point to the map and when the pointer <br>

  becomes a hand, click that area and <br>  we’ll show you our travel pictures and <br> stories from there!<br>

</font>

<img border=0 src=”US.gif” usemap=”#states” width=285 height=295> <map name=”states”>

<!-- Each coordinate pair links to its own page for that city --> <!-- San Diego -->

<area shape=rect coords=”26, 167, 56, 197” href=”http://www. BarkleyFamilyPage.com/Sd.htm”>

<!-- New York City -->

<area shape=rect coords=”239, 107, 268, 135” href=”http://www. BarkleyFamilyPage.com/NYC.htm”>

<!-- Miami, FL -->

<area shape=rect coords=”227, 209, 262, 239” href=”http://www. BarkleyFamilyPage.com/MI.htm”>

<!-- Toronto -->

<area shape=rect coords=”207, 93, 235, 118” href=”http://www. BarkleyFamilyPage.com/TO.htm”>

</map>

</td>

Image maps have drawbacks, such as the lack of support for alternative text that pops up descriptions of the hot spot. For simple matters, they work well, and for some Web page applications where maps and diagrams provide an overview for Web pages that follow, image maps are good to use.

Session 27—Adding Other Special Elements to the Web Site

375

Session 28 lists limitations of image maps.

Cross-Ref

If you’ve followed along for the past 27 sessions, you are much farther along than a newcomer to HTML! You are on your way to becoming an HTML programmer.

REVIEW

Add forms to get user feedback on your site.

Use image maps in those situations where a graphic image makes an effective navigation tool.

Use coordinate pairs to recognize where the user clicks on your page’s image maps.

QUIZ YOURSELF

1.What happens when the user clicks the Barkleys’ form’s Reset button? (See “Adding the Form to the Favorite Movies Page.”)

2.What happens when the user clicks the Barkleys’ form’s Submit button? (See “Adding the Form to the Favorite Movies Page.”)

3.What are two disadvantages to sending a form’s answers to yourself via e-mail? (See “Adding the Form to the Favorite Movies Page.”)

4.What is the difference between an image used as a hyperlink and an image map? (See “Creating the Image Map for the Family Travels Page.”)

5.What is one drawback to image maps? (See “Creating the Image Map for the Family Travels Page.”)

Session

Sunday—VI Part

27

Afternoon