Click here to Skip to main content
15,895,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to integrate javascript into it, but I have no clue what to do at this point.

What I have tried:

<html>
<head>

<script type="text/javascript" src="http://www.cpagrip.com/script_include.php?id=2193">
{ var link = document.getElementById('getNumber'); // Gets the link
link.onclick = getNumber; // Runs the function on click

function getNumber() {
var minNumber = 0; // The minimum number you want
var maxNumber = 100; // The maximum number you want
var randomnumber = Math.floor(Math.random() * (maxNumber + 1) + minNumber); // Generates random number
$('#myNumber').html(randomnumber); // Sets content of <div> to number
return false; // Returns false just to tidy everything up
}
</script>
</head>

<body>

<marquee scrollamount="<div id="myNumber"></div>"> Banana </marquee>
<br>
<marquee> banana </marquee>

</body>
Posted
Updated 28-Dec-16 18:10pm

1 solution

This feature is obsolete[^], try not to use it.
Just take it as an opportunity to learn some JavaScript coding is then fine:
First, if you want to generate a random number in a range, say min 10 to max 100 both inclusive, the logic should go like this:
1. Find the range, e.g. range = 100 - 10 = 90
2. As Math.random() will generate a random number from 0 (inclusive) to 0.9999..., this
Math.random() * (90 + 1)

will give a random number from 0 (inclusive) to 90.999....
3. use Math.floor() to get rid of the decimal part to get a number from 0 to 90.
4. Add the min 10 to this number, you will get a number from 10 (inclusive) to 100 (inclusive)
5. The resulting code will be:
JavaScript
Math.floor(Math.random() * (maxNumber - minNumber + 1)) + minNumber

Forget the code that you got from nowhere, try this:
HTML
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Marquee</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  var minNumber = 0;
  var maxNumber = 100;	
  $("#myNumber").attr("scrollamount", Math.floor(Math.random() * (maxNumber - minNumber + 1)) + minNumber);

});
</script>
</head>

<body>
<marquee id="myNumber"> Banana </marquee>
<br>
<marquee> banana </marquee>
</body>
</html>

It should scroll in random speed on each refresh of your browser tab.
To understand this code, you should attend jQuery Tutorial[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900