469,916 Members | 2,338 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,916 developers. It's quick & easy.

create a variable link

Hi,

I must begin to say that I'm rather new in wtiting and using JavaScript. Now
I want to use JavaScript in a HTML-page. On the homepage is a link. Every
time the homepage is displayed the link must point to another target. I want
to realize this by having a lot of differet targetpages. The names of these
pages are p1001.htm until p<nnnn>.htm. At this moment the last is p1153.htm,
but the amount is increasing every day.
I have a file named "counter.txt" which contains one line with the string of
the last targetpage, at his moment "1153".

My idea is to have a JavaScript which:
1. reads the file counter.txt to determine the last available page
2. then takes at random one number between 1001 and 1153,
3. sets the HREF-link to page p<random>.htm.

I know it must be possible in JavaScript, but can anyone help me?

Thanks,

Susan
Jul 23 '05 #1
1 1226
asd987 wrote:
Hi,

I must begin to say that I'm rather new in wtiting and using JavaScript. Now
I want to use JavaScript in a HTML-page. On the homepage is a link. Every
time the homepage is displayed the link must point to another target. I want
to realize this by having a lot of differet targetpages. The names of these
pages are p1001.htm until p<nnnn>.htm. At this moment the last is p1153.htm,
but the amount is increasing every day.
I have a file named "counter.txt" which contains one line with the string of
the last targetpage, at his moment "1153".

My idea is to have a JavaScript which:
1. reads the file counter.txt to determine the last available page
2. then takes at random one number between 1001 and 1153,
3. sets the HREF-link to page p<random>.htm.

I know it must be possible in JavaScript, but can anyone help me?

Thanks,

Susan

Use an SSI to include "counter.txt", format it something like the
following:

<p id="whatever" style="display:none">[number here]</p>
<script type="text/JavaScript">
var base=isNaN(document.getElementById("whatever").inn erHTML)?""
:+(document.getElementById("whatever").innerHTML);
if(base){
document.write("<a href="+
(1001 + Math.floor (Math.random() * (base-1001)) )+
".html>click</a>")
}
</script>

Not tested.
Mick

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Dr. Oz | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.