473,473 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to dynamically delete a row

10 New Member
Hi,
i am dyanamically creating rows.In which I have two columns. First column contains text box while second one contains a button. On click of this button I want to delete that row.
The problem is my code I always deletes the first row.
below is the code snipet:
Expand|Select|Wrap|Line Numbers
  1. function apendValues()
  2.  {
  3.      listAttrValues=true ;
  4.   var tbl = document.getElementById('tblAttrValues');
  5.   var lastRow = tbl.rows.length;
  6.   // if there's no header row in the table, then iteration = lastRow + 1
  7.   var iteration = lastRow;
  8.   var row = tbl.insertRow(lastRow);
  9.    row.id='row'+iteration;
  10.     var val = document.getElementById('newAttrVal').value;
  11.   // left cell
  12.   var cellLeft = row.insertCell(0);
  13.    var el = document.createElement('input');
  14.     el.type = 'text';
  15.     el.id = 'attrRow' + iteration;
  16.     el.size = 20;
  17.     el.name='attrCol';
  18.   //  el.readonly ='readonly';
  19.     el.setAttribute('readonly','readonly');
  20.     el.value=val;
  21.  
  22.   cellLeft.appendChild(el);
  23.  
  24.   // right cell
  25.   var cellRight = row.insertCell(1);
  26.   var e2 = document.createElement('input');
  27.   e2.type = 'button';
  28.   e2.name = 'deleteRow';
  29.   e2.value = '-';
  30.   e2.onclick=deleteSelectedRow;
  31.  
  32.   e2.id = 'txtRow' + iteration;
  33.    cellRight.appendChild(e2);
  34.  
  35.        //Clear text box
  36.        document.getElementById("newAttrVal").value = "";
  37.  
  38.   }
  39.  
  40.  function deleteSelectedRow()
  41.  {
  42.     document.getElementById("tblAttrValues").deleteRow(this); 
  43.      var cols=document.getElementsByName('attrCol');
  44.       for(var i = 0; i < cols.length; i++){
  45.        cols[i].id='attrRow' + i;
  46.          }
  47.    }
  48.  
Please help.
Jan 28 '09 #1
5 1650
hariomt
10 New Member
I have got the solution.
Jan 28 '09 #2
acoder
16,027 Recognized Expert Moderator MVP
Good to hear, but could you also post the solution, so that it can help other members/visitors coming across this thread.
Jan 28 '09 #3
hariomt
10 New Member
Expand|Select|Wrap|Line Numbers
  1. function deleteSelectedRow()
  2.  {
  3.       var tbl= document.getElementById("tblAttrValues")
  4.       tbl.deleteRow(this.parentNode.parentNode.rowIndex); 
  5. }
Jan 28 '09 #4
acoder
16,027 Recognized Expert Moderator MVP
Thanks for posting your solution. Just remember to use [code] tags though.
Jan 28 '09 #5
hariomt
10 New Member
I am sorry, I did not get you.
What do you mean by [code] tags?
could you please explain.
Jan 28 '09 #6

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

Similar topics

7
by: Ryan Taylor | last post by:
Hi. I have some code that dynamically generates a PDF and spits this content directly to the web browser. I use HTMLDoc to create the Pdf's from html. So the user can click on a button "Print...
37
by: yogpjosh | last post by:
Hello All, I was asked a question in an interview.. Its related to dynamically allocated and deallocated memory. eg. //start char * p = new char; ...
7
by: Yi | last post by:
Two questions about the following code sample: --- code begins --- //class IPv4 is defined elsewhere list<IPv4ip_list; for (int i=1; i<=9; i++) { char addr; sprintf(addr, "%d.%d.%d.%d",...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
0
by: vijendra | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file?I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
5
by: Amoril | last post by:
I've read quite a few different message on various boards and for some reason I'm still having trouble wrapping my head around this viewstate maintenance and trying to get these dynamically created...
10
by: Jess | last post by:
Hello, If I create a temporary object using a dynamically created object's pointer, then when the temporary object is destroyed, will the dynamically created object be destroyed too? My guess...
17
by: cygsoft | last post by:
Hi I have created a dynamic row and inserted the values into the cells of those rows from textboxes. Now I have to edit those values stored in the rows. At the end of each row created dynamically...
15
by: tom | last post by:
why delete the dynamically allocated memory twice causes an error, see the code below: int _tmain(int argc, _TCHAR* argv) { int *pi = new int(12); cout<<*pi; delete pi; delete pi; }
29
by: shivasusan | last post by:
Hi! I can add rows with inputs to my HTML table dynamically using DOM, but I cannot remove selected rows. In fact, every row contains a Delete button. So, user selects the rows to remove, clicks...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.