JavascriptProva

giovedì 12 gennaio 2012

Riempire un array con una casella di testo

Ecco un codice per l'immissione di dati in un array con una casella di testo:
<script>
var matrice=new Array();
function addArray(voce)
{
  matrice[matrice.length]=voce;
}


function listArray()
{
 for(var n=0;n<matrice.length;n++)
  document.write(matrice[n]+"<br>");
 document.close();
}
main();

</script>
<body>
<input type="text" id=casella>
<input type="button" value="aggiungi" onClick="addArray(document.getElementById('casella').value);document.getElementById('casella').value=''">
<input type="button" value="elenca" onClick="listArray()">
</body>

Nessun commento:

Posta un commento