Reputation: 1804
Once a user enters lets say 5 numbers into that list I want to have a reset button so if the user wants to delete them all instantly they can click reset which should delete the entire list....
I have tried making a reset button with a reset function that fetches the element by id and tries to delete it but it did not quite work so I am hoping someone here knows how to do that...
here is the fiddle http://jsfiddle.net/bikbouche1/QVUHU/67/
Upvotes: 0
Views: 33195
Reputation: 307
Don't forget that you could always just use a simple
<input type="reset" value="Reset">
if you want to clear the entire form. Note that you'll need to move those inputs that are currently outside of the form tags in your fiddle to within the form tags for this to work.
Here's an updated fiddle.
Also note that nrabinowitz's answer won't work for two reasons. First of all, the incorrect ID was given ("numbers" instead of "number") and also, .innerHTML will not work for an input field. Instead you should use:
document.getElementById("reset").onclick = function() {
document.getElementById("number").value = "";
};
An updated, working version of his fiddle is here.
Upvotes: 4
Reputation: 55688
See this updated fiddle. Key code:
document.getElementById("reset").onclick = function() {
document.getElementById("numbers").innerHTML = "";
};
To clarify, since this appears to have confused other posters - the "numbers" div
is a placeholder for one or more dynamically-created input
elements, not a reference to the original "number" input
. By setting innerHTML
to ""
, the above code deletes the dynamically created elements entirely - it's not trying to clear their values.
Upvotes: 2