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 6 of 6

Thread: Merging codes

  1. #1
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Merging codes

    Hi,

    i was wondering if anyone could help me.

    i have two bits of code

    <html>
    <body>
    <script type="text/javascript">


    number1 = parseInt(Math.random() * 6+1);
    number2 = parseInt(Math.random() * 6+1);
    number3 = parseInt(Math.random() * 6+1);
    number4 = parseInt(Math.random() * 6+1);

    document.write(number1 + "" + number2 + "" + number3 + "" + number4);


    document.write('<img src="die'+ number1 +'.bmp">');
    document.write(" ");
    document.write('<img src="die'+ number2 +'.bmp">');
    document.write(" ");
    document.write('<img src="die'+ number3 +'.bmp">');
    document.write(" ");
    document.write('<img src="die'+ number4 +'.bmp">');

    </script>
    </body>
    </html>

    This displays 4 random die images i have saved in file

  • #2
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    an this is the 2nd one


    <html>

    <body>
    <script type="text/javascript">

    function nextroll(){
    number1 = parseInt(Math.random() * 6+1);
    number2 = parseInt(Math.random() * 6+1);
    number3 = parseInt(Math.random() * 6+1);
    number4 = parseInt(Math.random() * 6+1);

    document.Score.display.value+=(number1 + "" + number2 + "" + number3 + "" + number4)+"\n";

    }

    document.write('<img src="die'+ number1 +'.bmp">');
    document.write(" ");
    document.write('<img src="die'+ number2 +'.bmp">');
    document.write(" ");
    document.write('<img src="die'+ number3 +'.bmp">');
    document.write(" ");
    document.write('<img src="die'+ number4 +'.bmp">');

    </script>

    <form name="Score">
    <center>
    <input type="button" value="roll" onclick=nextroll()>
    <input type="reset" value="reset">
    <textarea name="display" rows="20" cols="40" readonly></textarea>

    </form>

    </body>

    </html>

  • #3
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    as you can see in the 2nd one i want a button that on roll displays everything, and puts it into a text box

    it does that, but doesnt even display the image

    ive even tried making the function cover that action too

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your problem is two fold...

    Your images are never loading because the variables (number1, number2, ect...) although global are not defined on page load (they are defined when nextroll is called) when the document.write statements write your image tags to the page... Thus, the very first image looking for the variable number1 throws and error and the script quits right there (turn on error reporting so you can find these yourself)...

    And, even if the images loaded, there is nothing in your nextroll function to update the image sources... so naturaly the textarea is updated but the images will not be updated even if they were visible on the page....

    Suggestion: Place the images in the body of the document using names or ids along with default image sources and place your next roll in the head and change the image and either call the function window.onload or body onload changing the image sources whenever the function fires...

    Is this homework? Seems so...

    .....Willy

  • #5
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Willy Duitt
    Is this homework? Seems so.
    could be.
    see here for details
    *keep it simple (TM)

  • #6
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jbot
    Hmmmmm;

    Multiple online personalities...
    I suppose I should add both: jonnyheald & davegreen
    To my do not write code for list....

    Cheers and thanks for the heads up;
    .....Willy


  •  

    Posting Permissions

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