Skip to content
Advertisement

Clear input fields on form submit

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 :

JavaScript

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!

Advertisement

Answer

Use the reset function, which is available on the form element.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement