<input type="file" name="galleryImages{{ $key }}[]"
value="1"
data-default-file="{{ asset('storage/services/' . $service->slug . '/gallery/' . $key . '/' . $imageItem) }}"
class="dropify" data-id="{{ $key }}"
>
For each input field i want to get back the value of that clicked input.
$(document).ready(function() {
$('.dropify').dropify(); //initializing dropify
//Handling click event on Remove button of dropify
$('.dropify-clear').click(function(e) {
e.preventDefault();
console.log(e.target.value);
alert('Remove Hit', ); //Here you can manage you ajax request to delete
//file from database.
});
});
2
Answers
To get the ID or value of the Dropify input when clicking the remove button, you can use the following code:
In the code above,
$(this)
refers to the clicked remove button. By traversing the DOM, we can find the corresponding Dropify input element and retrieve its value using.val()
. Similarly, the ID of the input element can be obtained using.attr('id')
.Please note that this solution assumes that the structure of your HTML and the classes used by Dropify remain unchanged. If there are any modifications to the structure or class names, you may need to adjust the code accordingly.
To get the ID or value of the Dropify input on clicking the remove button (dropify-clear button), you can use the following code:
In the code above,
$(this)
refers to the clicked remove button. we can find the corresponding Dropify input element and retrieve its default value using.attr('data-default-file')
. Similarly, the ID of the input element can be obtained using.attr('data-id')
.Please note that we cann’t get the default value of the dropify input by
.val()
function because the default value is placed in the attribute (data-default-file)