How can I make a roulette in Javascript

Asked

Viewed 2,370 times

3

Well my question is this::

I have a form in HTML, which when pressing Submit it gives me a random number from 1 to 5 in PHP. What I wanted to know was, how could I get PHP to click the button and select one of the numbers 1 to 5 randomly and then send it to a simple javascript roulette to show the chosen number. In other words, the roulette simulated that rotated and fell on the chosen number.

  • 1

    Gonçalo, welcome to the site. Avoid creating new questions just to get more attention, if you need to change something just click the button editar just below your question. Visit the tour of the website for more information.

  • I don’t know if this is what you really want (slot machine effect), but it can be useful. Roulette.js

1 answer

0

To generate the random number in php use the function Rand(), it accepts two arguments the incial number and the end of an interval.

<?php
   $numero = rand(1 , 5);
   echo $numero;

The echo of the number can be done inside (value) of a Hidden input, so the value can be retrieved by javascript with document.getElementById().

Example - ideone

Browser other questions tagged

You are not signed in. Login or sign up in order to post.