0

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

DontVoteMeDown
  • 21,122
  • 10
  • 69
  • 105

2 Answers2

0

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

gijoe
  • 1,159
  • 7
  • 7
0

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');
    }
  });
 }
Omolewa Stephen
  • 444
  • 3
  • 19