I’m trying to learn javascript. For an exercise I want to make a page with a list, text box and a button. Pressing the button would add the text to my list. My code:
<html>
<head charset="utf-8">
<script type="text/javascript">
var array = new Array()
array.push("test")
function pusher() {
array.push( document.forms["former"]["finput"].value )
}
</script>
</head>
<body>
<form name="former" onsubmit="pusher()">
<input type="text" name="finput" />
<input type="submit" value="Submit" />
</form>
<ul type="disc">
<script type="text/javascript">
for (var i = 0; i < array.length; i++)
document.write("<li>"+array[i]+"</li>")
</script>
</ul>
</body>
</html>
If I add alert() to pusher(), I see that every time I click submit the elements are reset. So, how do I redraw my list without resetting the values of array?
Apparently elements of a HTML can be altered using the method
(figured it’s no good to keep a question unanswered)