Creating elements using a loop in JS.

Joined
Nov 19, 2024
Messages
1
Reaction score
0
I'm using AJAX to retrieve data from a MySQL Database and create a table. In the end column of the table, I want a series of buttons, to carry out different actions for that record (the same actions, using the same set of functions, just with a different record).

What I've tried is:

Code:
for (var line of liveFeedJSON) {

  //Create <tr> and <tds>

  tscButton = document.createElement('button');
  tscButton.innerHTML = '<span class="fa-solid fa-keyboard">';
  tscButton.className = 'actionButton';
  tscButton.onclick = function() {checkAction(this, currentUser, line['svcID'], 'shtTSC', 'System updated.');};

  functionsCell.appendChild(tscButton);
}

The trouble is, it seems to pass the arguments from the last line created, whichever button is clicked on and I can't work out how to get round this. Any ideas would be very welcome!

Thanks
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,007
Messages
2,570,266
Members
46,864
Latest member
DaniEbswor

Latest Threads

Top