I am trying to call input attribute value from child function.
Code is Here:
$("input.ups").fileinput({
uploadUrl: "/imalatci/products/uploadimages",
allowedFileExtensions: ["jpeg","jpg", "png", "gif"],
maxImageWidth: 500,
maxImageHeight: 400,
maxFileCount: 5,
resizeImage: true,
language:"tr",
uploadExtraData: function() {
return {
product_id: $(this).attr('product_id')
};
}
}).on('filepreupload', function() {
$('#kv-success-box').html('');
}).on('fileuploaded', function(event, data) {
$('#kv-success-box').append(data.response.link);
$('#kv-success-modal').modal('show');
});
I want to get $("input.ups") product_id attribute in this function:
uploadExtraData: function() {
return {
product_id: $(this).attr('product_id')
};
}
But it is getting undefined error?
How can we fix this ?
uploadExtraDatathethisreference will not be the element which raised the event. You should declare a variable with the data you require in the outer scope to use within that handler. You haven't shown a full example of your code, so I can't tell you exactly how to do this.