An Introduction of JavaScript - Image Maps

Web Hosting That Works
WebMail

Home Page

New To Websites
  Website Primer
  Site Costs

eCommerce
  About eCommerce
  Shopping Cart
  Merchant Account

Data Centers
  Web Servers
  Data Protection
  RAID & Archive

Web Hosting
  Virtual Host
  Managed
  Dedicated
  Compare Plans
  FAQ
  Cities We Serve

Domain Name
  Naming Tips
  Register

HTML
  FrontPage
  Page Design
  Images
  HTML Tags
  Color Chart

JavaScript
  Introduction
  Resourses

Database
  Database Demo
  MySQL
  DBI
  Perl
  PHP

Programming
  Perl   JavaScript
  JSP vs ASP
  Tips

CGI
  Basics
  Email Forms
  Example Form
  Counter

eMarketing
  Search Engines
  Interactivity
  Marketing 101

EMail
  About Email
  OutlookExpress
  Spam Filter
  Email Viruses

FTP
  WS_FTP Program



Web Host Ratings

 



Soup Up Your Image Map

Every serious Web cruiser has encountered image maps--you know, those graphics where clicking in different spots links you to different URLs. JavaScript lets you extend image maps even further. In our example, we give users more information when they click a particular brain.

First, we simply set up the functions that define the descriptive text for each half of the image map:

function leftDescription() {
  //the "
" character displays a line break
  document.orderForm.description.value =
"This is Lefty. She enjoys figuring the tip
on 
restaurant bills and sorting her 14 years'
worth 
of computer magazines by subject.";
}
function rightDescription() {
  document.orderForm.description.value =
"This is Righty. He likes making sand
castles and 
searching for connections
between old rock 
albums and classic movies.";
} 

The above code is simpler than it may look at first. It defines two functions, leftDescription() and rightDescription(). When either of these functions is called, the appropriate text is displayed in the text area named description in the form named orderForm.

Now all we have to do is call JavaScript functions instead of URLs when the user clicks. We'll do this by defining the image map like this:

<MAP NAME="brainMap">
<AREA NAME="leftHalf" COORDS="0,0,112,112"
HREF="javascript:leftDescription();">
<AREA NAME="rightHalf" COORDS="0,0,225,225"
HREF="javascript:rightDescription();">
</MAP> 

In this example, when a user clicks the left side of the image, the browser invokes the leftDescription() function. Similarly, when a user clicks the right side of the image, the code invokes the JavaScript function rightDescription().

Notice that when called from within an HREF, the name of the function to be invoked must be preceded by the javascript: string (for instance, HREF="javascript:leftDescription()"). This lets the browser know a JavaScript statement is coming up.

Now we just need to define some place to put the output text.

<IMG NAME="currentImage"
SRC="../../Images/java.window.gif" width=225
height=125 ALIGN="TOP" USEMAP="#brainMap">
<FORM NAME="orderForm">
<TEXTAREA NAME="description" COLS=40 ROWS=4>
</TEXTAREA>
</FORM> 

That's it. We've used HTML to tell the browser to use the brainMap image with java.window.gif. We've also defined a form called orderForm and inserted a text area in it called description. Now, when we click the map, the proper function activates and fills the text area with a description of the brain.

Next: Storing Data in the Browser .. Hu!




DaySite Web Hosting
1400 North Beach Street
Ormond Beach (Daytona), Florida 32174

386-672-6285
877-329-4839 (Sales Only Please)
Web@DaySite.Net
Cell Phone Email







Home | New To Websites | eCommerce | Web Hosting | Domain Name | HTML | Database | Programming | CGI | eMarketing | EMail | FTP

 
 
 

 

 


- Order Here -

Free
Domain Name Registration

With

Full Feature
Web Site Hosting

Just $15 a Mo.

Key Features
  Secure Servers
  Prof. Managers
  Personal Support
  Data Protection

Other Features
  Super Connectivity
  Ample Disk Space
  Extensive Email
  Spam Filters
  Virus Filters
  Web Site Stats
  CGI, Perl, PHP
  MySQL Database
  SSL Directory
  Free Domain Names

Call:
877-329-4839
(Toll Free)

eCommerce

FREE SSL

Secure Servers

Apache

Web Servers

MySQL Database Programming

Perl Database Programming

database programming

Since 1997

Domain Name Checker