0

As you see in the screenshot. I choose a file, leave the pop up without refreshing the page and open it again, and the file input still has the file I picked.

<input id="fileuploadbannermobile" type="file" name="files[]">

I try this when the pop up opened.

$("#fileuploadbannermobile").val('');

But it doesn't seem to solve the issue.

screenshot

3
  • Could you create a runnable snippet (and test that it does show the problem) thanks. See stackoverflow.com/help/minimal-reproducible-example Commented Dec 10, 2022 at 20:52
  • Also, use trigger('change'); Like :: $("#file").val('').trigger('change'); Commented Dec 10, 2022 at 21:05
  • The code you have should work fine. If it doesn't, it is something else you haven't shown here causing problems. How/when do you fire the reset? Commented Dec 10, 2022 at 23:13

1 Answer 1

1

Setting an input value to empty string or null should definitely work.

  • try setting a value to "" or null in vanila javascript

    yourInput.value = null or yourInput.value = ""

  • also check if you are setting those values to the right input

It would also be useful to know what browser you use.

Sign up to request clarification or add additional context in comments.

4 Comments

<input id="fileuploadbannermobile" type="file" name="files[]"> thats my file input btw. maybe other attributes are the problem
@Mert first, name can not be a list. I prepared you a fiddle, try it: Fiddle link
@AndrejNovák Why do you think plain JS will work when jQuery does not, I mean what do you think the problem is? Also, a name with square brackets like files[] is perfectly valid (example, example, example, ...)
@Don'tPanic you are right, i completely forget about that. "what do you think the problem is?" - at this point i can not be certain. Author did not provided the code where he is registering/executing events (during pop up opening), my guess is that the value setting is not triggered in any way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.