0
I’m having trouble making the button responsible for generating the alert with the draw number start javascript, I’m using the code below for javascript:
<script type="text/javascript">
$('#btnGnrt').click(function() {
function sorteio_numero(nummin, nummax, numqtd){
var amostra = new Array(),
lista = new Array(),
tamanho = 0,
aleatorio = 0;
for(var i = nummin; i <= nummax; i++){
amostra.push(i);
}
while( lista.length < numqtd ){
tamanho = amostra.length;
aleatorio = Math.floor( Math.random() * tamanho );
lista.push( amostra.splice(aleatorio,1) );
}
return lista;
}
alert(sorteio_numero(1000,9999,1));
</script>
and the next to the button:
<div class="button">
<br><button id="btnGnrt">Gerar Sorteio</button><br>
</div>
The page contains only the button and a header with the title, I can’t see the reason why the button "does not work"
in place of
aleatorio
, would not beresultado
?– Leandro Angelo
Probably has to do with the scope, try to put
$('#btnGnrt').click(function() {}
Within a$(document).ready(function(){});
– MarceloBoni
Yes, I had changed the "randomness" for "result" but I missed one, I corrected the question
– Natã Minetto
I wouldn’t have any problem with you calling
function
sorteio_numero noonclick
inline button, but... goes to taste– MarceloBoni
I put inside the $(Document). ready(Function(){}); and did not solve, I think I will try to call in onclick same
– Natã Minetto