I am downloading a table from a remote database but when I do this I am having an issue implementing a double click function on the rows in the table. I am able to do the double click function on the whole table though using just the id for the table like this $('#t01').dblclick(function(){. I think it is because I am generating the html text for the table on the server side. I tried using the function on the EditTable that I created fully on the client side and it worked fine. Has anyone any idea how I could get around this? Any help would be greatly appreciated!
html code:
<section class="main-section" id="service"><!--main-section-start-->
<div class="container">
<h2>Mapping</h2>
<div data-role="content">
<table id="t01">
</table>
<br>
<br>
<button data-role="button" id="upload">Upload</button>
<table id="EditTable">
<tr>
<td>1</td><td>One</td>
</tr>
<tr>
<td>2</td><td>Two</td>
</tr>
</table>
</div>
</div>
</section>
JavaScript code:
var trackID = new Array();
function onBodyLoad() {
$.ajax({
type: 'GET',
url: 'http://ec2*******************compute.amazonaws.com/downloadAdmin.php',
success: function (data) {
// document.getElementById("tblDiv").innerHTML = data;
var trackID=data.split(" ") ;
//alert(data);
printDatabase(trackID);
}
});
}
function printDatabase(trackID){
var tblText='<table style="width:100%"><tr><th style="text-align:center">Recent Journeys</th></tr>';
var len = trackID.length;
for (var i = 0; i < len; i++) {
tblText +='<tr id="\''+trackID[i]+'\'"><td style="text-align:center">'
+ trackID[i] +'</td></tr>';
}
tblText +="</table>";
document.getElementById("t01").innerHTML =tblText;
}
$(document).ready(function() {
$('#t01 tr').dblclick(function(){
alert('Row dblclicked');
});
});