Buy Now
Sign in

Javascript_JQuery code alteration for File upload with REPEATER

Elitakey , May 09 2019, 12:14
E
Elitakey 192
May 09 2019, 12:14 #386679
Hello, CF6 Masters,
Need a hint for the following - with different posts here I have sucesfully created JavaScript code for photo preview + filesize check.
Code works wery well for one file upload:
jQuery(document).ready(function(jQ) {
var uploadFile;

uploadFile = 'spFoto';
uploadFile = jQ('#'+uploadFile);
uploadFile.after("<div id='imagePreview'></div>");
jQ('#imagePreview').hide();
uploadFile.on('click', function() {
jQ('#imagePreview').hide();
});

uploadFile.on('change', function() {
var files, reader;
files = !!this.files ? this.files : [];
if( ((files[0].size/1024)/1024) > 5){
alert("File greater than 5MB!");
event.target.value = '';
return;
} else if ( /^image/.test(files[0].type) ) {
reader = new FileReader();
reader.readAsDataURL(files[0]);
reader.onloadend = function() {
jQ('#imagePreview').css('background-image', 'url(' + this.result + ')');
jQ('#imagePreview').show();
}
}
});
});
Now I need to implement this for the Repeater, where uploadFile will be something like this - spFoto0; spFoto1; spFoto2..... etc.
where File field name is - spFoto[{var:area_repeater38.key}] and ID - spFoto{var:area_repeater38.key}
How can I write this in Javascript? Tried diffferent ways - 'spFoto$k'; 'spFoto[$k]', 'spFoto[key]' etc.... nothing works.
Thank you in advance-
Elita
healyhatman 7
May 09 2019, 22:03 #386707
Try using begins with or ends with jQuery selectors
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
E
Elitakey 192
May 10 2019, 09:21 #386729
Hi, healyhatman, I wrote you the private message.