Hi. I want to start off by saying that I know, probably the solution is here somewhere but I will ask because I have tested for 3 - 4 hours some different methods.
My code is working fine until I click my buttons. Here is my code:
function traningData(data) {
var traning = data.val();
var keys = Object.keys(traning);
var data = [];
var text = "";
for (var i = 0; i < keys.length; i++) {
var k = keys [i];
var name = traning [k].name;
var desc = traning [k].description;
var uid = traning [k].uid;
var type = traning [k].type;
text += '<button onClick="readItemData('+name+')">'+name+'</button>';
The problem is in my onClick code for the button
onClick="readItemData('+name+')"
When I press the button to run my readItemData() I get the following error in the console
Uncaught SyntaxError: missing ) after argument list
How is it supposed to look inside the onClick when I try to pass it all as a string in to my text string?
UPDATE
Here is how the button looks when i inspect the element:
"<button onclick="readItemData(Bodyweight row)">Bodyweight row</button>"
SOLUTION
I could not sleep until i fixed this problem, so here is my solution,
"text += 'onclick="readItemData('+"'"+name+"'"+')">'+name+'';"