0
Good evening, I made a javascript logic of inputs receiving the value of an array, all right however, when you click on the button to happen the event the values appear and disappear from the input quickly, follow the code, Thanks.
<script>
var codigo = "23794130047008001672190051686005178110000010890"
var metade = Math.floor(codigo.length / 8);
var seis = Math.floor(codigo.length / 7);
var um = Math.floor(codigo.length/47);
var rest = Math.floor(codigo.length/3)
var res = codigo.substr(0,metade) + " ," + codigo.substr(5,metade) + " ," + codigo.substr(10,metade)
+ " ," + codigo.substr(15,seis) + " ," + codigo.substr(21,metade) + " ," + codigo.substr(26,seis)
+ " ," + codigo.substr(32,um) + " ," + codigo.substr(33,rest);
var div = res.split(" ,")
function separar(){
let teste = document.getElementsByTagName("input")
for(i =0; i< teste.length; i++){
teste[i].value = div[i]
console.log(teste[i].value = div[i])
}
}
</script>
<form id="form" >
<label>Digite o código</label>
<br/><button onclick="separar()">Separar</button>
<br/>
<br/>
<input type="text"/>
<input type="text"/>
<input type="text"/>
<input type="text"/>
<input type="text"/>
<input type="text"/>
<input type="text"/>
<input type="text"/>
</form>
What’s the idea? each input gets a value?
– JrD
Each input receives a value from the 'div' array, when I put the window.onload in front of Function the values already start correctly in the inputs, but without, when I click, it appears quickly and some.
– israel