I click on “Browse” or “Choose” button in a file field.
And select a file.
Unfortunately, I decided not to send any of the files via the upload form.
How should I remove the selected file in the form, without reloading the page?
I click on “Browse” or “Choose” button in a file field.
And select a file.
Unfortunately, I decided not to send any of the files via the upload form.
How should I remove the selected file in the form, without reloading the page?
The only way you can reset a file input field is by either doing one of the following:
Hi,
You can add the form field with a button to remove it, like this:
<div><input type="file" name="a_name" /> <span style="cursor:pointer;color:red;" onclick="this.parentNode.innerHTML=''">X</span></div>
Thanks MarPlo.
Here is my solution with a little modification that prevented multiple cancel options.
<!-- file replacement via upload -->
<span id="answer_image-upload">
<input type="file" name="answer_image" value="" class="file" id="answer_image-file" />
</span>
<span class="form-hints">
Or, upload a file now |
<a href="#" onclick="return !(document.getElementById('answer_image-upload').innerHTML=document.getElementById('answer_image-upload').innerHTML);">Cancel upload</a>
</span>