Forum Moderators: open
I have around 20 small images with the exact dimensions in pixels.
I would like to randomly display from the 20, 1 image plus corresponding textual description, everytime a surfer views the webpage. I need the image to be linkable also.
I have searched for the script but the closets I could come up with was the one below.
<script>
//Random link plus text description script
//specify total # of random links
var totallinks=4
var urls=new Array(totallinks)
var descriptions=new Array(totallinks)
var titles=new Array(totallinks)
urls[0]="http://www.eye4u.com"
descriptions[0]="Flash site with a kick"
titles[0]="Inside My Mind"
urls[1]="http://www.xeofreestyle.com"
descriptions[1]="Comprehensive flash and design"
titles[1]="techie"
urls[2]="http://www.billybussey.com/highband.html"
descriptions[2]="All Things Holy. A hand in flash/3d/photoshop"
titles[2]="Dynamic Drive"
urls[3]="http://www.frosch-studio.com"
descriptions[3]="Watch the frog"
titles[3]="The frog"
var MachoManRandomSavage=Math.floor(Math.random()*totallinks)
</script>
<script>
var cont=titles[MachoManRandomSavage]+"<br>"+descriptions[MachoManRandomSavage]
cont+="<br><a href='"+urls[MachoManRandomSavage]+"'>"
cont+=urls[MachoManRandomSavage]+"</a><br>"
document.write(cont)
</script>
<p><font face="arial" size="1">This critiques provided by</font><br>
<a href="http://www.teamphotoshop.com"><font face="arial,helvetica" size="1">Team Photoshop Members</font></a></p>
</body>
The above script, diplays random (4) links plus corresponding textual description.
It been a long time since I've done simple javascript, my arrarys/variables repertoire is minimal.
Can help me to configure this to my needs.
Randomly display 1 linkable image plus corresponding textual description?
Any help is greatly appreciated
Fess
All that you require to do is add another Array of image then add this to the outpur string... as below:
var totallinks=4
var image=new Array(totallinks)
image[0]="/img/test1.jpg"
image[1]="/img/test2.jsp"
image[2]="/img/test3.jpg"
image[3]="/img/test4.jpg"
</script>
<script>
var cont=titles[MachoManRandomSavage]+"<br>"+descriptions[MachoManRandomSavage]
cont+="<br><a href='"+urls[MachoManRandomSavage]+"'>"
cont+="<img src='"+image[MachoManRandomSavage]+"'><br>"
cont+=urls[MachoManRandomSavage]+"</a><br>"
document.write(cont)
</script>
Oh and remove the title from its Array and also the output string!
HTH,
-George
Thanks very much for your help in this matter.
Below, I did what you suggested. It works.
<script>
//Random link plus text description script
//specify total # of random links
var totallinks=4
var image=new Array(totallinks)
var urls=new Array(totallinks)
var descriptions=new Array(totallinks)
var titles=new Array(totallinks)
image[0]="http://www.example.com/image1.jpg"
urls[0]="http://www.eye4u.com"
descriptions[0]="Flash site with a kick"
titles[0]="Inside My Mind"
image[1]="http://www.example.com/image2.jpg"
urls[1]="http://www.xeofreestyle.com"
descriptions[1]="Comprehensive flash and design"
titles[1]="techie"
image[2]="http://www.example.com/image3.jpg"
urls[2]="http://www.billybussey.com/highband.html"
descriptions[2]="All Things Holy. A hand in flash/3d/photoshop"
titles[2]="Dynamic Drive"
image[3]="http://www.example.com/image4.jpg"
urls[3]="http://www.frosch-studio.com"
descriptions[3]="Watch the frog"
titles[3]="The frog"
var MachoManRandomSavage=Math.floor(Math.random()*totallinks)
</script>
<script>
var cont=titles[MachoManRandomSavage]+"<br>"+descriptions[MachoManRandomSavage]
cont+="<br><a href='"+urls[MachoManRandomSavage]+"'>"
cont+="<img src='"+image[MachoManRandomSavage]+"'><br>"
cont+=urls[MachoManRandomSavage]+"</a><br>"
document.write(cont)
</script>
The only thing I'm confused about is the following:
"Oh and remove the title from its Array and also the output string!"
You suggested I remove the title? The title meaning "totallinks"?
Also, I would like to have the URLS to say "click here" and link them to the approtiate pages.
I tried to insert this into to the output string but it did not work:
urls[0]="<a href="http://www.something.com" target="_blank">Click Here</a>"
any suggestions?
Thanks
Fess
I understand. Thanks for the correction.
Although when I place it into the output string:
urls[0]="<a href='http://www.something.com' target='_blank'>Click Here</a>"
The resulting html page, looks like this:
Click Here'>
Click Here
I suspect the tags are not suited for the array/variable or something.
Do you have any suggestions?
Thank You
Fess
Can you not do it the original way of:-
urls[0]=http://www.something.com
With the output handling the target="_blank" and click here
i.e.
cont+="<br><a href='"+urls[MachoManRandomSavage]+"' target='_blank'>Click here</a><br>"
If you post your current <script> where the document write is I shall see if I can ammend it to do what you are after.
-George