473,395 Members | 2,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

deleting a table row

hi,
i post my code below , if i click any remove button mean ,particular row should be removed.. but i cann't do this because the corresponding row ie tr value is not come code and also i do't know the corresponding delete code

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <script language = javascript>
  4. function adddisplay()
  5. {
  6. alert('hai');
  7. }
  8. function addRowToTable()
  9. {
  10. // Collect varible
  11. var jname=document.getElementById("name").value;
  12. var jid=document.getElementById("fid").value;
  13. var jage=document.getElementById("age").value;
  14. var jdept=document.getElementById("dept").value;
  15. var jpert=document.getElementById("pert").value;
  16. var jcgname=document.getElementById("clgname").value;
  17.  
  18.  
  19.  
  20.  
  21. var tbl = document.getElementById('tblSample');
  22. var lastRow = tbl.rows.length;
  23. // if there's no header row in the table, then iteration = lastRow + 1
  24. var iteration = lastRow;
  25. var row = tbl.insertRow(lastRow);
  26.  
  27.  
  28.  var i;
  29. for(i=0;i<=tbl.rows.length-1;i++)
  30. {
  31. var s=i;
  32. }
  33. alert(s);
  34.  
  35.  
  36. //var tr=document.createElement("tr");
  37. //tr.setAttribute('id', 'hid' + iteration);
  38. //tr.appendChild(tr);
  39. // left cell
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. var cellLeft = row.insertCell(0);
  50. var textNode = document.createTextNode(iteration);
  51. cellLeft.appendChild(textNode);
  52.  
  53.  
  54. //var tr=document.createElement("tr");
  55. //tr.setAttribute('id', 'hid' + iteration);
  56. //tr.appendChild(td);
  57.  
  58.  
  59. // right cell
  60. var cellRight = row.insertCell(1);
  61. var el = document.createElement('td');
  62. //el.setAttribute('type', 'textarea');
  63. el.setAttribute('id', 'did' + iteration);
  64. //el.setAttribute('size', '0');
  65. cellRight.appendChild(el);
  66. var texttt = document.createTextNode(jname+" "+jid+" "+" "+jage+" "+jdept+" "+jpert+" "+jcgname);
  67. cellRight.appendChild(texttt);
  68.  
  69. var cellremove= row.insertCell(2);
  70. var rr1 = document.createElement('input');
  71.  
  72. var i;
  73. for(i=0;i<=tbl.rows.length-1;i++)
  74. {
  75. rr1.setAttribute('type', 'button');
  76. rr1.setAttribute('value','Remove' + i);
  77. rr1.setAttribute('id', 'rid' + iteration);
  78. rr1.setAttribute('size', '40');
  79. rr1.onclick=function() {deleteRow(i)};
  80. cellremove.appendChild(rr1);
  81. }
  82.  
  83. }
  84.  
  85. function deleteRow(click_id)
  86. var tbl = document.getElementById('tblSample');
  87. var lastRow = tbl.rows.length;
  88. var iteration = lastRow;
  89. var row = tbl.insertRow(lastRow);
  90.  
  91.  
  92. var rid=document.getElementById('did');
  93. //for( var i=1<=tbl.rows.length-1;i++)
  94. //{
  95.  
  96.  
  97.  if(click_id=="3")
  98. {   alert(click_id);
  99. document.getElementById('rid')[i].style.display='none';
  100.  
  101. //}
  102. }
  103.  
  104. }
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111. //*function editRowFromTable()
  112. //{
  113.  
  114. //javascript:document.body.contentEditable='true'; document.designMode='on'; void 0
  115. //document.getElementById("b1").addEventListener("edit", function(ev) {
  116. //  if (checkbox.selected)
  117. //{
  118. //}
  119. //}
  120. //}
  121.  
  122.  
  123. </script>
  124.  
  125. <form id="first">
  126. NAME:<input type="text" id="name"><br>&nbsp;&nbsp;&nbsp;&nbsp;<br>
  127. ID:<input type="text" id="fid"><br>&nbsp;&nbsp;&nbsp;&nbsp;<br>
  128. AGE:<input type="text" id="age"><br>&nbsp;&nbsp;&nbsp;&nbsp;<br>
  129. <b>QUALIFICATION:</b><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
  130. DEPT:<input type="text" id="dept"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
  131. PERCENTAGE:<input type="text" id="pert"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
  132. COLLEGE NAME:<input type="text" id="clgname"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
  133. <input type="button" value="Submit" id="submit" onclick="adddisplay();"><br>
  134.  
  135. <input type="button" value="Add" onclick="addRowToTable();" />
  136.  
  137. <input type="button" id="r1" value="Remove" onclick="deleteRow(this.id);" />
  138. <input type="button" id="b1" value="Edit" onclick="editRowFromTable();" />
  139.  
  140. <table border="1" id="tblSample">
  141.  
  142. </table>
  143.  
  144. </form>
  145. </body>
  146. </html>
Mar 28 '12 #1
1 1655
acoder
16,027 Expert Mod 8TB
Use deleteRow and change your code to use the click_id parameter.
Mar 28 '12 #2

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

Similar topics

3
by: ScottH | last post by:
I was looking for thw SQL to delete dupes from a table, and came across this. All who saw it agreed in principle, but I can't quite figure out the logic. If we are deleting all rows whose rowid...
1
by: Jay | last post by:
Hi I have a huge table with over 100million records and on regular basis ineed to delete nearly a million records and insert a million records. Currently I delete indexes before going through the...
3
by: Nathan Bloom | last post by:
Hi, I have a data entry form (access 2000) that also allows the user to add, update, and delete records from the form. The Delete action is carried out in an event procedure and has the...
1
by: Mark | last post by:
Not sure this is the right place for this questions, but here goes: I get an error message when deleting an table from a Access database. The code is as follows and the error message is after...
4
by: stokefan | last post by:
Hi all, I wondered if anyone knew if it was possible to delete entries in an MS Access database table from just entering data into it? I shall explain : If you have a web form (in asp.net...
0
by: rob | last post by:
I have a visio file that models a database. I added a view to the project but then decided to delete it again. I simply hit the delete key after which I got a dialog saying: "Remove selected item...
2
by: awebguynow | last post by:
Most JS people have seen sorttable.js and similar implementations. I'm trying to do a SubSelect of an existing table, restricting values in a Column to spec. range. Rows manipulated through...
2
by: sajithamol | last post by:
How we can find out by Query that wether a particular table exists?
4
by: sphinney | last post by:
I'm not exactly sure how to start this post. My question is pretty simple, but it will take a little bit of context before I can state it. (And thanks in advance for taking the time to read this!) ...
13
by: ramprakashjava | last post by:
hi, i hav "java.lang.NullPointerException" error while Deleting table records using checkbox in jsp here i enclosed files help quickly plzzz.. ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.