0
Hello.
I want to return the success message if a name is inserted into the array. And I want to display the names in that array.
I don’t want to use Alert(). Document.write doesn’t work well in functions, especially with events or timer functions. I have tested with timers and events, but other things appear on the screen and not what I want. Already with Alert() works. There is another output command?
Or maybe, I can use php to display the success message and array names. As a step from javascript to php?
Follow two javascript functions for such.
<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>
Here is functioning normally with the
getElementById
, including thedocument.write
.– Edilson