By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,627 Members | 1,870 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,627 IT Pros & Developers. It's quick & easy.

deleting/adding row in tables using image button

P: 1
i have 3 4 row of tables which is having dd,textboxes i wanted to delete rows using imagebutton which is along with that row. when u click that button that perticular row should delete it should in AJAX can u help me
Dec 14 '11 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
why would you use AJAX for deleting a HTML element?

let's say you have
Expand|Select|Wrap|Line Numbers
  1. <tr>
  2.   <td>
  3.     <img src="del.gif" class="delete" alt="delete row">
  4.   <td>
  5. <tr>
since the click event knows on which element (<img>) it operates, you can climb up to the next <tr> and delete that.
Expand|Select|Wrap|Line Numbers
  1. function delete_row()
  2. {
  3.   // get the current element
  4.   var current_node = this;
  5.   // climb up the DOM tree
  6.   while ("tr" != current_node.nodeName.toLowerCase()) {
  7.     current_node = current_node.parentNode;
  8.   }
  9.   // delete
  10.   current_node.parentNode.removeChild(current_node);
  11. }
  12. // get all delete-images
  13. var del = document.getElementsByClassName("delete");
  14. // attach event to all images
  15. for (var i = del.length; i--;) {
  16.   del[i].addEventListener("click", delete_row, true);
  17. }
note: if you used a JS library like jQuery, that code becomes even easier.
Dec 14 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.