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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script modification help

Status
Not open for further replies.

afCindy

IS-IT--Management
Jan 23, 2003
9
US
I am trying to avoid using iframes on the site I'm building because of some crossbrowser issues.

Anyhow I'm trying to display a random image everytime the page is loaded, but also give the user the option to manually change the image.

I don't write javascript code, but am a eager copy paster. I was hoping for help modifying a script slightly, so it allows the user to simply change the image by the click of a buttom (as well), -as opposed to refreshing the entire page (which is a pain for dail-up users). My problem is I don't know how I do that and still keep the randomization code. I would be greatful for help.

code is as follows:

<!--

// ***********************************************
// AUTHOR: LLC
// URL: // Use the script, just leave this message intact.
// Download your FREE CGI/Perl Scripts today!
// ( )
// ***********************************************

function image() {
};

image = new image();
number = 0;

// imageArray
image[number++] = &quot;<img src='images/indexpic1.jpg' border='0'>&quot;
image[number++] = &quot;<img src='images/indexpic2.jpg' border='0'>&quot;
image[number++] = &quot;<img src='images/indexpic3.jpg' border='0'>&quot;
image[number++] = &quot;<img src='images/indexpic4.jpg' border='0'>&quot;
image[number++] = &quot;<img src='images/indexpic5.jpg' border='0'>&quot;
image[number++] = &quot;<img src='images/indexpic6.jpg' border='0'>&quot;
image[number++] = &quot;<img src='images/indexpic7.jpg' border='0'>&quot;
image[number++] = &quot;<img src='images/indexpic8.jpg' border='0'>&quot;
// keep adding items here...

increment = Math.floor(Math.random() * number);

document.write(image[increment]);

//-->

Thanks
Karina
 
this ought to do it - click on the image to change it.

[tt]
function image() {
};

image = new image();
number = 0;

// imageArray
image[number++] = &quot;images/indexpic1.jpg&quot;;
image[number++] = &quot;images/indexpic2.jpg&quot;;
image[number++] = &quot;images/indexpic3.jpg&quot;;
image[number++] = &quot;images/indexpic4.jpg&quot;;
image[number++] = &quot;images/indexpic5.jpg&quot;;
image[number++] = &quot;images/indexpic6.jpg&quot;;
image[number++] = &quot;images/indexpic7.jpg&quot;;
image[number++] = &quot;images/indexpic8.jpg&quot;;
// keep adding items here...

increment = Math.floor(Math.random() * number);

document.write('<img src=&quot;' + image[increment] + '&quot; border=&quot;0&quot; onclick=&quot;change(this);&quot; />');

function change(oImg) {
oImg.src = image[Math.floor(Math.random() * number)];
}

//-->
[/tt]
=========================================================
if (!succeed) try();
-jeff
 
yes - first, modify this line from:[tt]
document.write('<img src=&quot;' + image[increment] + '&quot; border=&quot;0&quot; onclick=&quot;change(this);&quot; />');[/tt]

to:[tt]
document.write('<img name=&quot;oImg&quot; src=&quot;' + image[increment] + '&quot; border=&quot;0&quot; onclick=&quot;change(this);&quot; />');[/tt]

then you can use a button like:[tt]
<input type=&quot;button&quot; value=&quot;Change&quot; onclick=&quot;change(document['oImg']);&quot; />[/tt]


=========================================================
if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top