I need to grab the id of this query output; that is, I need to get the delete button to grab its associated id so it’ll delete the correct row. When the results are output, there is a delete button for each row. But clicking on the delete button has no effect. (This works in Chrome, not FF.) I’m using:
function renderResults(tx, rs) {
e = $('#previous_scores');
e.html("");
for(var i=0; i < rs.rows.length; i++) {
r = rs.rows.item(i);
e.html(e.html() + '<button id="button_delete" onClick="deleteScores(this.id)">Delete</button> id: ' + r['id'] + ', hole ' + r['hole_num'] + ' strokes: <strong>' + r['num_strokes'] + ',</strong> email: ' + r['email'] + '<br><br>');
}
}
I also tried:
onClick="deleteScores(' + r['id'] + ')">
It should call:
function deleteScores(id) {
db.transaction(function(tx) {
tx.executeSql('DELETE FROM Strokes WHERE course_id = id');
});
renderScores();
}
At the bottom of the page I have:
<script>
var el = document.getElementById("button_delete");
if(el){
el.addEeventListener("click", deleteScores);
}
</script>
The DB is composed of:
function insertScore(hole_num, num_strokes, course_id, email) {
db.transaction(function(tx) {
tx.executeSql('INSERT INTO Strokes (course_id, hole_num, num_strokes, email) VALUES (?, ?, ?, ?)', [course_id, hole_num, num_strokes, email]);
});
}