Hello.
I want to return the success message if a name is entered in the array. And I want to display the names in that array.
I do not want to use alert (). Document.write does not work well on functions, especially with events or timing functions. I have already tested timers and events, but other things appear on the screen and not what I want. Already with alert () it works. Is there another output command?
Or maybe, I can use php to display the success message and array names. How do I move from javascript to php?
Here are two javascript functions for this.
<script>
j = 0;
i = 0;
nomes = new Array();
function inserirNome() {
nome = prompt("informe o nome");
nomes[i] = nome;
alert("Nome inserido");
i++;
}
function verNomes() {
while (j < i) {
alert(nomes[j]);
j++
}
if (i == 0) {
alert("Não tem nome inserido");
}
}
</script>
<a onclick="inserirNome()"> Inserir um nome</a>
<a onclick="verNomes()"> Ver os nomes inseridos</a>