www.webdeveloper.com
Results 1 to 11 of 11

Thread: Help required for simple code

  1. #1
    Join Date
    Nov 2012
    Posts
    4

    Help required for simple code

    Hi,

    I have written a simple little random number generator program. However, with my limited knowledge I just can’t get the output result that I want.

    This is the code:

    <!DOCTYPE html>
    <html>
    <body>
    <p id="demo">Click the button to Generate a Tracker Code.</p>
    <button onclick="myFunction()">Generate Tracker Code</button>
    <script>
    function myFunction()
    {
    var x=document.getElementById("demo")
    x.innerHTML=Math.floor((Math.random()*10000000000)+1);
    }
    </script>
    <STYLE type="text/css">
    BODY {text-align: center}
    </STYLE>
    </body>
    </html>

    It works well but what I want is just a simple displayed return as in the example below without giving the opportunityto generate another number.

    For example I would just like the answer to be:

    “Your Tracker Code Is”
    XXXXXXXXXX

    I am sure the answer is simple but so am I.

  2. #2
    Join Date
    Mar 2011
    Posts
    1,139
    Code:
    <!DOCTYPE html>
    <html>
    <style type="text/css">
    #demo {text-align: center}
    </style>
    <body>
    <p id="demo">Your Tracker Code Is<br>
    <script>
     document.write( Math.floor((Math.random()*10000000000)+1) );
    </script>
    </p>
    </body>
    </html>
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Nov 2012
    Posts
    4
    Thanks for the reply Rick but this just gives me the display on page open. I want to be able to click on the button on the start page then get that answer on a landing page but without showing the button again as per my original code.

  4. #4
    Join Date
    Mar 2011
    Posts
    1,139
    Code:
    <!DOCTYPE html>
    <html>
    <style type="text/css">
    #demo, #result {text-align: center}
    </style>
    <script>
     function myFunction() {
     document.getElementById('demo').style.display = 'none';
     document.getElementById('result').innerHTML = '<p>Your Tracker Code is:<br>' +  Math.floor((Math.random()*10000000000)+1) ;
      }
    <body>
    <div id="demo">
    <p>Click the button to Generate a Tracker Code.</p>
    <button onclick="myFunction()">Generate Tracker Code</button>
    </p>
    </div>
    <div id="result"></div>
    </body>
    </html>
    Rick Trethewey
    Rainbo Design

  5. #5
    Join Date
    Nov 2012
    Posts
    4
    Rick,

    I have tried to run your code above but just get a blank screen.

  6. #6
    Join Date
    Mar 2011
    Posts
    1,139
    Sorry.. I forgot the closing </script> tag.
    Code:
    <!DOCTYPE html>
    <html>
    <style type="text/css">
    #demo, #result {text-align: center}
    </style>
    <script>
     function myFunction() {
     document.getElementById('demo').style.display = 'none';
     document.getElementById('result').innerHTML = '<p>Your Tracker Code is:<br>' +  Math.floor((Math.random()*10000000000)+1) ;
      }
    </script>
    <body>
    <div id="demo"> 
    <p>Click the button to Generate a Tracker Code.</p>
    <button onclick="myFunction()">Generate Tracker Code</button>
    </p>
    </div>
    <div id="result"></div>
    </body>
    </html>
    Rick Trethewey
    Rainbo Design

  7. #7
    Join Date
    Nov 2012
    Posts
    4
    Hi Rick,

    I also missed the closing </script> tag.

    Thank you once again for altering my code for me.

    Best regards.

  8. #8
    Join Date
    Mar 2011
    Posts
    1,139
    Sorry.. I forgot the closing </script> tag.
    Code:
    <!DOCTYPE html>
    <html>
    <style type="text/css">
    #demo, #result {text-align: center}
    </style>
    <script>
     function myFunction() {
     document.getElementById('demo').style.display = 'none';
     document.getElementById('result').innerHTML = '<p>Your Tracker Code is:<br>' +  Math.floor((Math.random()*10000000000)+1) ;
      }
    </script>
    <body>
    <div id="demo"> 
    <p>Click the button to Generate a Tracker Code.</p>
    <button onclick="myFunction()">Generate Tracker Code</button>
    </p>
    </div>
    <div id="result"></div>
    </body>
    </html>
    Rick Trethewey
    Rainbo Design

  9. #9
    Join Date
    Nov 2012
    Posts
    1
    Thanks for sharing this code. this code is really helpful.

    thanks,

  10. #10
    Join Date
    Dec 2012
    Posts
    9
    thanks for the info, I have been very useful



    Elevadores de coches | Maquinaria para taller mecanico

  11. #11
    Join Date
    Jul 2012
    Posts
    24
    That's good but how can i implement these code.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles