...

View Full Version : display image in javascript



cwl157
02-11-2004, 01:14 AM
here is the code how would I successfully display the image:


<html>
<head>
<script>
image01= new Image()
image01.src="head.jpg"
image02= new Image()
image02.src="tail.jpg"
</script>
</head>
<body>
<script>
<img src="head.jpg" name="h">
<img src="tail.jpg" name="t">
function cflip() {
var random=Math.floor(Math.random()*3)
num_1=parseInt(document.a.heads.value);
num_2=parseInt(document.a.tails.value);
if(random==1) {
document.a.heads.value=num_1+1
document.images[0]
}
else if(random==2) {
document.a.tails.value=num_2+1
document.images[1]
}
}
</script>



<form name="a">
<input type="button" name="flip" value="Flip coin" onClick="cflip()">
<br>
<input type="text" name="heads" value="0">
<input type="text" name="tails" value="0">
</form>
</body>
</html>


Thanks

glenngv
02-11-2004, 04:47 AM
...
if(random==1) {
document.a.heads.value=num_1+1
document.images['coin'].src=image01.src;
}
else if(random==2) {
document.a.tails.value=num_2+1;
document.images['coin'].src=image02.src;
}
...
<input type="text" name="heads" value="0">
<input type="text" name="tails" value="0">
<img src="transparent.gif" name="coin">
</form>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum