The JavaScript Diaries: Part 11

By Lee Underwood

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>

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();

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";

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

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.

Page 5 of 6

Previous Page
1 2 3 4 5 6
Next Page

  • Web Development Newsletter Signup

    Invalid email
    You have successfuly registered to our newsletter.
Thanks for your registration, follow us on our social networks to keep up-to-date