0

I've been having some troubles with this javascript code and I am looking for a suggestion. I am programtically adding a row to a table with javascript but I need to add an onclick event for each row. Problem is when the row adds to the page the quotations and upper / lower case has been all converted to lower case causing issues on the web page.

here is the current code

 var row = $("<tr id=" + id + " onclick=return SelectRow('Racks','" + id + "') >");

if someone could explain how to get it so that the ending result looked like this

<tr id="r1" onclick="return SelectRow('Racks','r1')">
</tr>

I'm guessing it has to do with escape characters and the order they are being placed but I can't seem to figure it out.

user1984027
  • 111
  • 1
  • 7

1 Answers1

2

Don't try to generate JavaScript inside HTML inside JavaScript. It is a right pain.

Don't write 90s style code. Stop using onclick attributes. Use event handlers bound with JavaScript.

function row_click_handler(event) {
    return SelectRow("Racks", this.id);
}
var row = $("<tr />").attr("id", id).on("click", row_click_handler);
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335