I would like to do the reverse of this script, in this script you click the GENERATE button, it generates 4 digits
What I want to do is the inverse, I want to declare the variable "1298105" (or whatever) and click Generate and it generates below a% of the% "1298105XXXX" result as declared in <div>
How do you do, any examples?
function gerar() {
// numero aleatorios
var numeros = [];
for (var i = 0; i < 4; ++i) {
var sorteio = Math.floor(Math.random() * 9);
if (sorteio == 0)
sorteio = 1; // 1 - 9
numeros[i] = sorteio;
}
var senha = numeros.join('');
document.getElementById('txtsenha').value = senha;
}
<input type="text" name="txtsenha" id="txtsenha"/>
<input type="button" value="Gerar" onclick="javascript:gerar()"/>