spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / javascript / diaries / 11

[previous] [next]

Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


The JavaScript Diaries: Part 11

Next, we'll create a link to it in the head section of the Web page we want to use it on:

<script type="text/javascript" src="hideMail.js"></script>

Then, we'll place some links for the actual e-mail addresses on our page. Here is where the output from the actual script is displayed.

<ol style="margin-top: 1pt">
  <li><script type="text/javascript">document.write(userName[0])</script></li>
  <li><script type="text/javascript">document.write(userName[1])</script></li>
  <li><script type="text/javascript">document.write(userName[2])</script></li>
  <li><script type="text/javascript">document.write(userName[3])</script></li>
  <li><script type="text/javascript">document.write(userName[4])</script></li>
  <li><script type="text/javascript">document.write(userName[5])</script></li>
  <li><script type="text/javascript">document.write(userName[6])</script></li>
  <li><script type="text/javascript">document.write(userName[7])</script></li>
  <li><script type="text/javascript">document.write(userName[8])</script></li>
  <li><script type="text/javascript">document.write(userName[9])</script></li>
  <li><script type="text/javascript">document.write(userName[10])</script></li>
  <li><script type="text/javascript">document.write(userName[11])</script></li>
</ol>

You don't have to place them all together; you could spread them out. The actual link you would use is:

<script type="text/javascript">document.write(userName[0])</script>

so you could have something like:

If you need further help, you can contact our Technical Service Manager at:
  <script type="text/javascript">document.write(userName[8])</script>.

which would display as:

If you need further help, you can contact our Technical Service Manager at: .

The important thing to remember is to change the index number to correspond with the index number in the array. For example, if we wanted to make a link to the address for mrobbins, whose entry in the array is userName[9]="mrobbins";, then we would place the following link on the page where we wanted it to display: <script type="text/javascript">document.write(userName[9])</script> as the index number is "9" for mrobbins.

If you wanted to display the person's name in the link instead of their e-mail address, you could use a parallel array like this:

var userName = new Array();
  userName[0]="msmith";
  userName[1]="bjones";
  userName[2]="ladams";
  userName[3]="bstevens";
  userName[4]="blarsen";
  userName[5]="rschwartz";
  userName[6]="msmithers";
  userName[7]="pclark";
  userName[8]="sakman";
  userName[9]="mrobbins";
  userName[10]="lcrazy";
  userName[11]="webmaster";

var userNameFull = new Array();
  userNameFull[0]="Mike Smith";
  userNameFull[1]="Brenda Jones";
  userNameFull[2]="Larry Adams";
  userNameFull[3]="Brent Stevens";
  userNameFull[4]="Bob Larsen";
  userNameFull[5]="Randy Schwartz";
  userNameFull[6]="Mary Smithers";
  userNameFull[7]="Pat Clark";
  userNameFull[8]="Sandy Akman";
  userNameFull[9]="Marty Robbins";
  userNameFull[10]="Louie Crazy";
  userNameFull[11]="Contact Us";

var siteName = "mydomain.com";

i=0;
do userName[i]='<a href="\"mailto:'" + username[i] + '@' + sitename>' + userNameFull[i] + '</a>';
  while(userName[++i])

Be sure the index numbers of the e-mail addresses and the names are the same.

When we begin looking at the DOM (Document Object Model) we'll be writing some of these scripts differently due to the interaction between JavaScript and the DOM.

home / programming / javascript / diaries / 11

[previous] [next]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

Created: November 24, 2005

URL: