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.
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
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.
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
Rick,
I have tried to run your code above but just get a blank screen.
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
Hi Rick,
I also missed the closing </script> tag.
Thank you once again for altering my code for me.
Best regards.
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
Thanks for sharing this code. this code is really helpful.
thanks,
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
Forum Rules
Bookmarks