Reputation: 37
I have a table of data that is presented like so:
<table>
<tr><td>Value 1</td></tr>
<tr><td>Value 2</td></tr>
<tr><td>Value 3</td></tr>
</table>
I'd like to pass the text between the two "td" tags into an Ajax function; ideally you click on the table entry and the table entry's value will be used to form a SQL query via Ajax. I however do not know how to pass each unique table entry into the Ajax function; I can't provide different ids for each table entry because the table is generated dynamically from another SQL query, nor do I know how to set up an ajax function to recognize dynamically generated ids. What's the best way to tackle this problem?
Upvotes: 0
Views: 116
Reputation: 22486
Add a click event listener to the table td elements and pass the html content of the clicked element to your ajax function.
$("table td").click(function () {
$.ajax({
url: 'path_to_file',
data: {
'table_value' : $(this).html()
}
});
});
Upvotes: 2