-1
I’m early in web development. The script below only works for what I do in the first for, I don’t know what I’m doing wrong. When he should do the second part is he doesn’t even get into it. It also doesn’t call Alert right after the first loop for. It’s like right after the first one he stops.
`
var setUnid = document.getElementById('unidadeVenda').value;
var setUnid2 = document.getElementById('unidadeVendaAux');
var unidDesc = '{% getIdUnidade %}';
var array = unidDesc.split(',');
var descUnid;
for (i = 0; i < array.length; i++) {
descUnid = array[i].split(':');
if (descUnid[1].trim() == setUnid) {
setUnid2.value = descUnid[0].trim();
}
}
alert('TESTE');
var setCom = document.getElementById('agente').value;
var setCom2 = document.getElementById('agenteVendaAux');
var comDesc = '{% getIdAgente %}';
var arrayCom = comDesc.split(',');
var descCom;
for (i = 0; i < arrayCom.length; i++) {
descCom = arrayCom[i].split(':');
if (descCom[1].trim() == setCom) {
setCom2.value = descCom[0].trim();
alert(descCom[0].trim());
}
}
Can you merge HTML? how do you know it doesn’t enter second
for
? some error on the console?– Sergio
Good morning Sergio, I discovered that the problem is when I use Trim(). For example in the first is " descUnid[1]. Trim() " did not understand the reason, but if used in this way ".
– gross
What gives
console.log(typeof descUnid[1]);
?– Sergio
console.log(typeof descUnid[1]); gives string, but I saw that one of the information gave "Undefined"
– gross