Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Photos in JavaScript

Status
Not open for further replies.

Chris75

IS-IT--Management
Jan 31, 2001
19
US
We had the following code built for us.

var txtList = new Array()
txtList[txtList.length]="RWS Building Company is a multiple recipient of the Business First Fast Fifty Award";
txtList[txtList.length]="SINCERITY:communicating with our clients with candor and respect";
txtList[txtList.length]="RELIABILITY:meeting deadlines, keeping promises and building a long-term relationship.";
j=parseInt(Math.random()*txtList.length);
j=(isNaN(j))?0:j;
document.write(txtList[j]);

It changes the phrase each time the page is refreshed. Is there a way to remove the sayings and replace them with pictures? If so, how?
 
you can.

use document.write(&quot;<img src=\&quot;image.jpg\&quot;>&quot;);

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Tried replacing txtList.length with document.write (left the []'s and = in), then put in &quot;<img src=\&quot;image.jpg\&quot;>&quot;; and it returned &quot;undefined&quot; in that area on the webpage. What did I do wrong?
 
make sure to change all the txtList values from &quot;RWS Building Company is a multiple recipient of the Business First Fast Fifty Award&quot; etc... to &quot;image1.jpg&quot;, &quot;image235.jpg&quot; etc...

then change [tt]
document.write(txtList[j]);
[/tt]
to:[tt]
document.write('<img src=&quot;' + txtList[j] + '&quot; />');
[/tt]
this is assuming your images are in the same directory as the .html file. otherwise you can add the path info to the txtList[] array elements, like so:
[tt]
txtList[txtList.length] = &quot;../images/img1.jpg&quot;;
[/tt]
=========================================================
if (!succeed) try();
-jeff
 
This is the script now:

var txtList = new Array()
txtList[txtList.length]=&quot;F:\Pics\Beechwold5.jpg&quot;;
txtList[txtList.length]=&quot;F:\Pics\Leadscope2.jpg&quot;;
txtList[txtList.length]=&quot;RELIABILITY:meeting deadlines, keeping promises and building a long-term relationship.&quot;;
j=parseInt(Math.random()*txtList.length);
j=(isNaN(j))?0:j;
document.write('<img scr=&quot;&quot; + txtList[j] + &quot;&quot; />');

We are getting nothing in the area. Pics are located in the Pics folder and names are correct.

We also have the first JavaScript on the page using the same txtList array. Could that be a problem?
 
you must use :

document.write('<img src=&quot;pathtoimages'+txtList[j]+'&quot;>');

as i don't know if the elements of txtList have the path to the imagens, i put there pathtoimages that you should replace for the Path to the images dir.
Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Chris,

2 things:

1. remove &quot;F:\&quot; from your image path if &quot;pics&quot; is a subfolder of the script's location.

2. you've misspelled &quot;src&quot;:
document.write('<img scr=&quot;&quot; + txtList[j] + &quot;&quot; />');
should be
document.write('<img src=&quot;&quot; + txtList[j] + &quot;&quot; />'); =========================================================
if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top