The JavaScript Diaries: Part 11/Page 5
[previous] [next]
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.
[previous] [next]
Created: November 24, 2005
URL: