I know this is continuously asked anew, and I've checked out different answers and tried different solutions but to no avail. In some cases it can be really be a case by case thing depending on how the code has been redacted.
I'd like to simply have the two input fields in my page to clear when I click submit (&& enter - unless its a separate event, that's for another thread), considering I always press enter as opposed to clicking - this is a site just meant for my use.
I have of course a input tag, type submit, and its working fine. But I also already have a specific onSubmit function :
function onSubmitForm(e) { e.preventDefault(); var var1 = document.getElementById("name"); var var2 = document.getElementById("review"); arrayOne.push( {name:var1.value,review:var2.value} ); localStorage.filmDatabase = JSON.stringify(arrayOne); document.getElementById("eyedee").innerHTML += '<p>' + '<span class=name>' + var1.value + '</span>' + '<span class=review>' + var2.value + '</span>'; }
I'm guessing its just about putting one line of (right) code, most probably at the end of the block but I just couldn't figure it out. Thanks a lot for the help!
That solution helped me: if you are using google Chrome, try this: Put the mouse pointer on the entry that you want to delete, press Delete . If the entry is not removed, press Shift + Delete .
You can easily reset all form values using the HTML button using <input type=”reset”> attribute. Clicking the reset button restores the form to its original state (the default value) before the user started entering values into the fields, selecting radio buttons, checkboxes, etc.
You can use preventDefault method of the event object. Show activity on this post. Alternatively, you could use event.
Use the reset function, which is available on the form element.
var form = document.getElementById("myForm"); form.reset();
You can clear out their values by just setting value to an empty string:
var1.value = ''; var2.value = '';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With