473,396 Members | 1,871 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,396 software developers and data experts.

how to dynamically delete a row

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;
  22.   cellLeft.appendChild(el);
  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;
  32.   e2.id = 'txtRow' + iteration;
  33.    cellRight.appendChild(e2);
  35.        //Clear text box
  36.        document.getElementById("newAttrVal").value = "";
  38.   }
  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.    }
Please help.
Jan 28 '09 #1
5 1648
I have got the solution.
Jan 28 '09 #2
16,027 Expert Mod 8TB
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
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
16,027 Expert Mod 8TB
Thanks for posting your solution. Just remember to use [code] tags though.
Jan 28 '09 #5
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

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...
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; ...
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",...
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...
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...
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...
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...
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...
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; }
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...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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,...
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...
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: 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...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.