i need some help please i spent forever just searching and trying to know why nothing is happening when i click that button
html:
<td></td>
<td></td>
<td></td>
<td><button id="<?php echo($row['ID']); ?>" onClick="delord()" class="del" style="font-size: 12">delete</button></td>
jquery:
function delord(){
var x = event.target.id;
$.ajax({
url: 'delorder.php?id=' + x,
success: function(){
alert('deleted');
}
});
}
i tried to type alert(x);
inside my jquery code and it returned the value then i tried to go to "delorder.php?id=335" and the row has deleted successfully
just when i try it with ajax its not working
A cross platoform way is to pass the event object in the onclick method like this
onclick="delord(event)"
then register the function as
function delord(e){
e = e || window.event;
var target = e.target;
var id = target.getAttribute('id')
}
e
will be the event and then your can grab the target element button
Do these
<table>
<thead>
<tr>
<td>Name</td>
<td></td>
</tr>
</thead>
<tbody>
<tr>
<td>Stephen</td>
<td><button onclick="deleteRow('delete',<?php echo($row['ID']); ?>)">Delete</button></td>
</tr>
</tbody>
</table>
jQuery:
function deleteRow(action,id){
$.ajax({
url: 'delorder.php?id=' + id,
success: function(){
alert('deleted');
}
});
}