Uncaught error : Invalid or unexpected Token

AgrebiAlaa
Kilo Explorer

this code in client script give me this error ' uncaught error : invalid or unexpected token ' 

this is the line of code :   document.getElementsByName(id)[0].innerHTML+='<button class="btn btn-default btn-sm" id='+element.files[i].name+' onclick="removeFiles('+id+',this.id)">'+ element.files[i].name + element.files[i].size+'KB <i class="fas fa-trash-alt"></i>  '+'</button>'+' .</br>'+''; 

any solutions ? Thanks .

4 REPLIES 4

Harsh Vardhan
Giga Patron

can you check the function parameter you have used in onClick, is that correct  ?

 

onclick="removeFiles(id,this.id)"  // try to change the parameter you have passed . 

this is the function removeFiles : 2 parameters id and file name 

removeFiles = function(id,fname) {
console.log('removing '+fname);
document.getElementById(fname).remove();
activity_attch.forEach(function(item){
if(item.id == id ){
for(var i=0;i<item.list;i++){
if(f.name==fname){
item.list.splice(i,1);
}

}
}
});

}

can you try to pass the parameter as i had mentioned in onclick . and see if it's giving you an error ? 

that mean i pass id and this.id in the definiton of function removeFiles?