I'm trying to create a remove button to clear the value for a <input type="file">. The problem I have is that I don't know how can I make each button point to their respective <input>.
I'm using the JQuery plugin ezdz to upload and create previews of the images and I can easily add the buttons to each input with the $ezdz predefined var:
$ezdz.parent('div').find('div.arrow_box').html('<p><a href="#" onClick="window.resetMethod($(this.form[\'file[]\']));return false;">Quitar imagen</a></p>');
$ezdz.parent('div').find('div.arrow_box').removeClass('hide');
I need to create a function to reset the file input:
window.resetMethod =
function (e) {
$(this).parent('div').find('input').get(0).reset();
}
But the problem is in the button...
<a href="#" onClick="window.resetMethod($(this.form[\'file[]\']));return false;">Quitar imagen</a>
This is the html code:
<div class="first">
<!-- ezdz creates the following div and it'll be the container for the img -->
<div>Drop a file</div> <!-- This div is $ezdz -->
<input type="file" name="file[]" accept="image/jpeg" /><div class="arrow_box hide"></div>
</div>
Any idea to make this working?
EDIT: Sorry I didn't realized that function will reset the entire form. I need to reset the input above the button.
I'm getting the following error in console:
TypeError: $(...).parent(...).find(...).get(...) is undefined