How to clear an HTML file input using JavaScript

If you are using file input in the form, you may need to clear the input after submitting the form. So today we will show you how to clear an HTML file input using JavaScript.

Way to clear an HTML file input

  1. Set the empty or null value
  2. Replace a new input file element value with the old element value

1. Set the empty or null value

For the modern browser, we can set the empty or null value.

Example:

2. Replace a new input file element value with the old element value

In this second method, we will create a new file input element and replace the value of the new element with the old element value.

Example:

That’s it for today.
Thank you for reading. Happy Coding..!! 🙂

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *