Forum Moderators: open

Message Too Old, No Replies

onclick to load new image

onclick

         

Deewhyren

6:41 am on May 7, 2006 (gmt 0)



Hi People,

I'm fairly new to javascript (it shows).
I've nearly created a web page that displays images in one part of the page. Using onclick for a previous/ next arrangement. I want to load in the prev or next image.

And its not working.

I did it to randonly display the images in the array, but when I susbstitute this for onclick, it doesn't work. The two functions I use are rightimage and leftimage().

Help!

Thanks

Andy.

Here is the relevant code.

function leftimage()
{

var choice= choice--;
document.write('<IMG SRC="'+imageArray[choice]+'" height="400" width="370" border="0">');

}

function rightimage()
{
//document.stock_photo.src="next.gif";

document.write('<IMG SRC="'+imageArray[choice]+'" height="400" width="370" border="0">');

choice++;
}
// Write out an IMG tag, using a randomly-chosen image name.
var choice = pickRandom(n);
//var choice = 9;
// -->
</script>

<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>

<body >
<table width="100%" height="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<table width="760" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="right" valign="bottom"><ul id="navMenu"><li id="NavSelected"><a HREF="Jane Home.htm">&nbsp;&nbsp;&nbsp;home&nbsp;&nbsp;&nbsp;</a></li><!--
--><li><a HREF="profile.htm">&nbsp;&nbsp;profile&nbsp;&nbsp;</a></li><!--
--><li><a HREF="editorial.htm">&nbsp;editorials&nbsp;</a></li><!--
--><li><a HREF="books.htm">&nbsp;books&nbsp;</a></li><!--
--><li><a HREF="contact.htm">&nbsp;&nbsp;contact&nbsp;&nbsp;</a></li></ul></td>
</tr>
</table>

<table width="760" border="0" cellpadding="0" cellspacing="0">
<tr>

<td width="19">
<img SRC="images/corner1.gif" width="19" height="19" /></td>
<td bgcolor="#FFFFFF">
<img SRC="images/spacer.gif" width="371" height="19" /></td>

<td rowspan="3">

<td rowspan="3"><SCRIPT LANGUAGE="JavaScript">document.write('<IMG SRC="'+imageArray[choice]+'" height="400" width="370" border="0">');</SCRIPT></td>

<form>
<input type="button" value="previous"
onClick="leftimage()">
<input type="button" value="forward"
onClick="rightimage()">
</form></script></td>


</div>

</tr>
<tr>
<td bgcolor="#FFFFFF">
<img SRC="images/spacer.gif" width="19" height="362" /></td>
<td align="left" valign="top" bgcolor="#FFFFFF" >
<img SRC="JClogo.jpg" width="300" height="250"><br>

<br><br><br>

mehh

2:32 pm on May 7, 2006 (gmt 0)

10+ Year Member



var choice = pickRandom(n);

i think this is your problem. do you have a function called pickRandom() also n hasnt got a value