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

How do i increase the rows in the table which has a delete option on each row

6
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. table,td
  6. {
  7. border:1px solid #393;
  8. }
  9. </style>
  10. </head>
  11. <body>
  12.  
  13. <p>Click the buttons to create and delete row(s) for the table.</p>
  14.  
  15. <table id="myTable">
  16. <tr>
  17. <td>No</td>
  18. <td>Description</td>
  19. <td>Unit Price</td>
  20. <td>Quantity</td>
  21. <td>Amount</td>
  22. <td>Delete row</td>
  23. </tr>
  24.  
  25. <tr>
  26. <td><input type="text" size = "2" name="no" placeholder="  No" ></td>
  27. <td><input type="text"   name="description" placeholder="  Description" ></td>
  28. <td><input type="text"   name="unit_price" placeholder="  Unit Price" ></td>
  29. <td><input type="text"   name="quantity" placeholder="  Qty" ></td>
  30. <td><input type="text"   name="amount" placeholder="  Amount" ></td>
  31. <td><input type="button" value="Delete" onclick="deleteRow(this)"></td>
  32. </tr>
  33. </table><p>
  34.  
  35. <hr></hr>
  36.  
  37.  
  38.  
  39. <button onclick="myCreateFunction()">Create row</button> 
  40.  
  41.  
  42. <script>
  43. function myCreateFunction()
  44. {
  45. var table = document.getElementById("myTable"); 
  46.   {
  47.  
  48. var a = '';
  49. var b = '';
  50. var c = '';
  51. var d = '';
  52. var e = '';
  53.  for(var i = 1; i <= 1; i++)
  54.  {
  55.     a += '<input type="text"   name="no'+i+'" placeholder="  No'+i+'" >';
  56.     b += '<input type="text"   name="description'+i+'" placeholder="  Description'+i+'" >'; 
  57.     c += '<input type="text"   name="unit_price'+i+'" placeholder="  Unit Price'+i+'" >';
  58.     d += '<input type="text"   name="quantity'+i+'" placeholder="  Qty'+i+'" >';  
  59.     e += '<input type="text"   name="amount'+i+'" placeholder="  Amount'+i+'" >'; 
  60.     f += '<input type="button"  name = "delete '+i+'" value="Delete'+i+'" onclick="deleteRow(this)'+i+'">';
  61.     }
  62.  
  63.  
  64.  
  65.   var row = table.insertRow(-1);
  66.   var cell1 = row.insertCell(0);
  67.   var cell2 = row.insertCell(1);
  68.   var cell3 = row.insertCell(2);
  69.   var cell4 = row.insertCell(3);
  70.   var cell5 = row.insertCell(4);
  71.   var cell6 = row.insertCell(5);
  72.  
  73.  
  74.   cell1.innerHTML =  a;
  75.   cell2.innerHTML =  b;
  76.   cell3.innerHTML =  c;
  77.   cell4.innerHTML =  d;
  78.   cell5.innerHTML =  e;
  79.   cell6.innerHTML =  f;
  80.  
  81.   }
  82. }
  83.  
  84.  
  85. function deleteRow(r)
  86. {
  87. var x = r.parentNode.parentNode.rowIndex;
  88. document.getElementById("myTable").deleteRow(x);
  89. }
  90.  
  91. </script>
  92.  
  93.  
  94. </body>
  95. </html>
  96.  
  97. <table> 
  98.     <tr> 
  99.     <td><input type="text" onblur="calcTotal(this, 'tot')" /></td> 
  100.     <td><input type="text" onblur="calcTotal(this, 'tot1')" /></td> 
  101.     </tr> 
  102.     <tr>     
  103.     <td><input type="text" onblur="calcTotal(this, 'tot')" /></td> 
  104.     <td><input type="text" onblur="calcTotal(this, 'tot1')" /></td> 
  105.     </tr> 
  106.     <tr>     
  107.     <td><input type="text" onblur="calcTotal(this, 'tot')" /></td> 
  108.     <td><input type="text" onblur="calcTotal(this, 'tot1')" /></td>        
  109.     </tr> 
  110.     <tr>     
  111.     <td><input type="text" id="tot" /></td> 
  112.     <td><input id="tot1" type="text" /></td> 
  113.     </tr>    
  114.     </table>
Aug 1 '14 #1

✓ answered by Dormilich

why would you do that?

10 1461
Dormilich
8,658 Expert Mod 8TB
why would you do that?
Aug 1 '14 #2
Eddu
6
i choose to do that because i want to create additional rows on the click of the button. Each row should have a delete button
Aug 1 '14 #3
Dormilich
8,658 Expert Mod 8TB
so you want to know how to add rows? (your "description" is ambiguous in this regard)
Aug 1 '14 #4
Eddu
6
Pardon my ambiguity, I do want to add rows. Could you help me out
Aug 1 '14 #5
Dormilich
8,658 Expert Mod 8TB
see line #65, that’s where you create a row. adapt that part and bind it to a click event.
Aug 1 '14 #6
Eddu
6
I have changed the value to a positive integer and it did not create any row. what do you mean by a click event? Thanks
Aug 1 '14 #7
Dormilich
8,658 Expert Mod 8TB
when you hit a button a click event is emitted. and you need these events to react to them.
Aug 1 '14 #8
Eddu
6
Could you please edit the code so i could understand better. My javascript skills(rookie). Thanks
Aug 1 '14 #9
Dormilich
8,658 Expert Mod 8TB
you wouldn’t understand a bit if I did that.

nevertheless, understanding events in JS is crucial since all user interaction depends on that.

http://www.smashingmagazine.com/2012...sponding-user/
Aug 1 '14 #10
Eddu
6
Thanks dude for you time
Aug 1 '14 #11

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

Similar topics

0
by: Gordon | last post by:
I have 2 tables t and t1. In this case, t1 is a copy of t. I want to delete rows from t1 based on criteria on the t table and a relationship between t ad t1 (in this case the id column). In the...
1
by: Ray | last post by:
Hello all, I am attempting to delete multiple rows from multiple tables as follows: DELETE FROM attachments,responses,response_lines WHERE attachments.id IN(2,7,11) AND...
2
by: garima puri | last post by:
hi, iwant to add dynamically some rows in same textarea when a button of addRows is clicked. like,if i have 2 rows in a textarea then after clicking a button the rows must be increased to 4....
1
by: Lars Netzel | last post by:
Hey! I need to make it possible for a user to delete items from a ListView. I want it to be as similar to Windows as possible so I want it to happen if I press Delete or with a RightClick menu...
1
by: bjaeger | last post by:
A few months back I was "playing" with an Access 2000 application I created. I somehow disabled the delete option from all menus, toolbars, and context menus. Now I cannot do any maintenance on...
2
by: LillianH via AccessMonster.com | last post by:
Suddenly all of my database have the delete option grayed out when I open them. HOW do I change this. It appears the database is read only. I cannot delete tables, modify queries , etc. I...
1
by: ChrisC | last post by:
Hello, I am attempting to create a trigger to keep track of changes to a table, mainly about specific changes to the data in the table. I had hoped that triggers defined as for each row would...
5
by: rajsrmc | last post by:
hello pals! i am using mysql database connected in grid view with aspx pages how to use delete option with check boxes (like hotmail inbox) suggestions will be really helpful thanks in advance
2
by: pragal | last post by:
Hi to all, I am new to php I am making a new web site, I want to display a table value in data grid view in a php page with edit and delete option for all values of the table. Please help me with...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.