I have several dynamic forms on a page that each have a file input... How do I do I target the correct file input using $(this) in javascript?
Here is my form
<form enctype="multipart/form-data" action="category_manage.php" method="post">
<div class="plus-button-container">
<input id="upfile" name="photo" type="file" onchange="submitFormAfterImageCheck();"/>
</div>
<input type="hidden" name="sml_image" value="sml_image" />
</form>
And here is my javascript function
function submitFormAfterImageCheck() {
var formSubmit = $(this).closest("form");
var file = $(this).closest('input[type=file]').val();
alert(file);
}
//gives me undefined
I also tried this that works, but only for the first form ...
function submitFormAfterImageCheck() {
var formSubmit = $(this).closest("form");
var file = $('input[type=file]').val();
alert(file);
}
I think I need something like this, but this gives me undefined
var file = $(this).find('input[type=file]').val();
var file = $('input[type=file]', formSubmit).val();