I want to create more then one image in a for-loop. It works fine, except that every Image should get a dbclick eventlistener. This is also not the problem.
In the eventlistener, I call a function. This function gets some parameters (e.g. the id of the image).
When I start an alert, I get always the same id.
My code :
function loadImageAttribute(imageid,link) {
var doc = document.getElementById("iframe_editor").contentWindow.document;
alert(imageid); // --> Always get the last id of the last image
openWindow('windowimagechange');
}
function insertImage() {
for (var i = 0; i < list.files.length; i++) {
var file = list.files[i];
if ('name' in file) {
txt += "name: " + file.name + "<br>";
}
if ('size' in file) {
txt += "size: " + file.size + " bytes <br>";
}
document.getElementById("counterImage").value = parseInt(document.getElementById("counterImage").value)+1;
var range= sel.getRangeAt(0);myParent=document.getElementById("iframe_editor").contentWindow.document.body;
var img=document.createElement("img");
img.src = "./fileuploads/"+file.name;
img.id = "imgid"+document.getElementById("counterImage").value;
myParent.appendChild(img);
range.insertNode(img);
doc.body.appendChild(p);
img.addEventListener( 'dblclick', function(){
loadImageAttribute(img.id,'');
},img.id);
}
}
When I check the eventlistener in the debug mode, I can see that als eventlistener get the right id.