Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2003
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 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
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 251 Times in 247 Posts
    ...
    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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •