I've been trying to get this script to work. I made a PHP random number generator and I'm trying to get it to feed to my main php page and update a div with the number generated whenever I push a button.
It works, kind of. It generates the number one time and no matter how many times you push the button afterwards, it doesn't update the element anymore.
I thought that I might have to clear the element first, so I added that in and it still doesn't work. Below is my code for index.php and randomRoller.php
<?php
include("./includes/randomRoller.php")
?>
<style type="text/css">
#cookies {
width: 50px;
height: 100px;
background-color: #000000;
color: #ffffff;
}
#bunnies {
width: 100px;
height: 500px;
background-color: #555555;
color: red;
}
</style>
<script>
function roll() {
document.getElementById('bunnies').innerHTML = '';
document.getElementById('bunnies').innerHTML = '<?php echo(roll()) ?>';
}
</script>
<button type="button" onClick="roll()">Test</button>
<div id="cookies">
</div>
<br>
<br>
<div id="bunnies">
</div>
./includes/randomRoller.php
<?php
function roll() {
return rand(1 , 200);
}
?>
Any hints or advice you can give me would be much appreciated.