PDA

View Full Version : random image code doesnt work


Random
09-30-2001, 09:36 PM
<script language="javascript">
pic=Math.round(Math.random()*2)

if(pic==1){var imag="<img src="splashes/splash.gif" width="500" height="500" usemap="#Map" border="0"><map name="Map"><area shape="rect" coords="0,0,250,501" href="http://www.static2k.com/index.shtml"><area shape="rect" coords="250,2,554,541" href="http://www.static2k.com/karph/index.shtml"></map>"}

if(pic==2){var imag="<img src="splashes/splash1.gif" width="500" height="500" usemap="#Map" border="0"><map name="Map"><area shape="rect" coords="0,0,250,501" href="http://www.static2k.com/index.shtml"><area shape="rect" coords="250,2,554,541" href="http://www.static2k.com/karph/index.shtml"></map>"}

document.write(imag)
</script>

any ideas why it doesnt work? it should just show up a random image bewtween 1 and 2 for now, but i will add more later...

myron
09-30-2001, 11:08 PM
One problem is you can't nest double quotes within double quotes like you're trying to do. Try changing the inner quotes to single quotes, so the code like

var imag="<img src="splashes/splash.gif"...

changes to something like this:

var imag="<img src='splashes/splash.gif' ...

El_Nino
10-01-2001, 12:28 AM
Myron is right. If you change that it should work.

Akido
10-07-2001, 11:05 AM
Just use PHP, it's easier to make a random script in :)