i'm pretty new to Javascript and I have an issue i can't seem to resolve. I would like to get user inputs from the same input text field and then place them in an array. First input goes in the array[0] position second in the array[1] position and so on. My setup is below but i have no success.
<!DOCTYPE html>
<html>
<head>
<title>Save Session</title>
</head>
<body>
<form>
<input type = "text" id = "testInput"></input>
<input type = "button" value = "Make Array" onClick = "makeArray()"> </input>
<input type = "button" value = "See Result" onClick = "seeResult()"></input>
</form>
<script type = "text/javascript">
function makeArray(){
var userInput = document.getElementById("testInput").value;
sessionArray = [];
for(i = 0; i < 5; i++){
sessionArray[i] = userInput;
break;
}
return sessionArray;
}
function seeResult(){
alert(makeArray())
}
</script>
</body>
Aucun commentaire:
Enregistrer un commentaire