sdfgg45 sdfgg45 - 2 months ago 6
jQuery Question

How to clear the img placeholder for choose image using jQuery

I have a form with fileupload.

<input class="file" type="file" name="files[]">


I am curently cloning the input, but if a file is choosen it also clones the choosen filinput, is there a way to clear the selected image?

script:
$('.fieldset-content_doc').first().clone().appendTo('.fieldset-clone_doc').find('.file').reset();


fieldset-content_doc: holds the formvalues

Answer

Apparently the issue is only reproducible on Firefox. But, you can simply set the value property of the element to null:

$('.fieldset-content_doc')
    .first()
    .clone()
    .appendTo('.fieldset-clone_doc')
    .find('.file')
    .each(function() { this.value = null; });

See Fiddle

Comments