3
If I put one break
in the first loop if
, simply does not work or execute anything.. It seems that the break
is read first of all, even without entering the condition if
. What’s the matter?
function verifynasc(field) {
var nascimento = field.value;
alert(nascimento);
if (nascimento.length > 10) {
alert("entrou no if");
}
nascimento = nascimento.replace('/', '');
var dia = '';
var mes = '';
var ano = '';
for (var i = 0; i < nascimento.length; i++) {
if (i < 2) {
var dia = dia + nascimento.charAt(i);
continue
} else if (i < 4) {
var mes = mes + nascimento.charAt(i);
continue
} else {
var ano = ano + nascimento.charAt(i);
}
}
var data = ano + "-" + mes + "-" + dia;
document.getElementById('date').value = data;
}
What is the problem you have? can you explain it better? (suggestions however: use
nascimento = nascimento.replace('/', '');
instead of thisreplaceAll
, and joinvar
inside the go to stayfor (var i = 0; etc...
)– Sergio
Problem is, I wanted that when you enter for IF condition it de-break up! only that if I break to do such action, even not entering the IF condition my code goes to bag. all my document that is contained the javascript codes do not work.. replaceAll I use to replace all and not only one, was a function I created for this.
– Ale
@Alexandrec.Caus If your loop starts on
0
and the firstif
forehead fori < 2
then he at all times will enter theif
and he at all times will come out of the loop at this point! If you’re saying your code whole stops working when placing thebreak
, can only be a syntax error (you wouldn’t be by chance puttingbreak
andcontinue
in the sameif
, would be? And by the way, always use;
, does not matter if the language requires it or not). Open in Chrome for example, and see on the console if it is displaying syntax error.– mgibsonbr
if it is another, this one you are pointing is the second, before the loop itself is.
– Ale
@Alexandrec.Caus, what values can have the variable
nascimento
?– Sergio