Web Analytics Made Easy -
StatCounter display image in javascript - CodingForum

Announcement

Collapse
No announcement yet.

display image in javascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • display image in javascript

    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

  • #2
    ...
    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>
    Glenn
    vBulletin Mods That Rock!

    Comment

    Working...
    X