I'm relatively new to HTML/JQuery. I'm currently trying to add a row from one table to another table with an onclick function. Here is the table containing the rows I want to add if clicked on:
<table class="tables" id="playerSearchTable" >
<% for (var i = 0; i < res1.length; i++) { %>
<form>
<tr class="player_search_tr">
<td class="playerTeamTableName1<%=i%>" id="player_name_submit" width="250px"><%= res1[i].Name %></td>
<input type="hidden" id="player_name<%=i%>" value="<%= res1[i].Name %>" />
<input type="hidden" id="player_pos<%=i%>" value="<%= res1[i].position_summary %>" />
<td width="90px" style="padding-left: 25px;" ><%= res1[i].position_summary %></td>
<td class="playerTeamTableName" width="90px" style="padding-left: 25px;"><%= res1[i].team_abbrv %></td>
<td width="120px" style="padding-left: 25px;"><%= res1[i].league_abbrv %></td>
</tr>
</form>
<% } %>
</table>
And here is my function:
$(document).ready(function(){
ul = document.getElementById("playerSearchTable");
li = ul.getElementsByTagName('tr');
for (i = 0; i < li.length; i++) {
player_name = li[i].getElementsByClassName("playerTeamTableName1"+i);
$(player_name).click(function(){
var name = $("#player_name" + i).val();
var pos = $("#player_pos" + i).val();
player_table_list = document.getElementById("playerSearchTable1");
var markup = "<tr class=\"player_search_tr\"><td width=\"60px\"></td><td width=\"300px\">" + name + "</td><td width=\"90px\">" + pos + "</td></tr>";
$('#playerSearchTable1').append(markup);
});
}
});
However, when I run the code above the rows that get inserted contain the value "undefined" for each cell. What am I missing here?