473,326 Members | 2,127 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,326 software developers and data experts.

how to use insertBefore to apend a line in between the table

123 100+
Currently, my code is alright if I just need to add a new line the end of
the line. First, my code to clone the second and third tr from the table,
then add the clone line the end of list.

But how can I write another "append" so I can add line in between the line?
i try insertBefore, but not works. Please help. thanks.


My html code
Expand|Select|Wrap|Line Numbers
  1.     <table border=0 cellpadding=5 cellspacing=0 id="quotetable">
  2.         <tr class='stdtext' align='center'>
  3.         <td>Start Date</td>
  4.         <td>End Date</td>
  5.         <td colspan=2 class="blackstdtext" style="font-size: 7pt" colspan=3>[<a href="javascript:void(0)" onClick="AddQuoteLine()">add line</a>]</td>
  6.     </tr>
  7.  
  8.    <tr>
  9.            <td><input name='form_startdate[]' value='' size=10 class=stdbox></td>
  10.            <td><input name='form_enddate[]' value='' size=10 class=stdbox></td>
  11.            <td><img src='../images/trash.gif' border=0 onClick='RemoveLine(this)'></td>
  12.            <td style='font-size: 7pt'>[<a href='javascript:void(0)' onClick='ShowSiteDetails(this)'>
  13.            <td colspan=2 class="blackstdtext" style="font-size: 7pt" colspan=3>[<a href="javascript:void(0)" onClick="AppendQuoteLine()">Apend line</a>]</td>
  14. override site     </a>]</td>
  15.       </tr>
  16.   <tr class='hidetext'>
  17.     <td colspan='10'>
  18.       <table border=0 align='left' cellpadding='1' cellspacing='1' class='stdtable'>
  19.         <tr><td bgcolor="#c7e2f9">
  20.           <table border=0 width=100% bgcolor="#c7e2f9">
  21.             <tr class='tinytext' align='center'>
  22.               <td>Contact Name</td>
  23.               <td>Address 1</td>
  24.             </tr>
  25.             <tr>
  26.               <td><input name='form_sitecontactname[]' value='' size='15' class='stdbox'></td>
  27.               <td><input name='form_siteaddress1[]' value='' size='10' class='stdbox'></td>
  28.             </tr>
  29.           </table>
  30.         </td></tr>
  31.       </table>
  32.     </td>
  33.   </tr>
  34.  
  35.       </table>

.js file code
Expand|Select|Wrap|Line Numbers
  1. function AddQuoteLine(sourceobj) {
  2.         var parenttableobj = document.getElementById("quotetable");
  3.         var tablebodies = parenttableobj.getElementsByTagName("tbody");
  4.         //alert(tablebodies);
  5.         var tableobj = tablebodies[0];
  6.         //alert(tableobj);
  7.         if (tableobj) {
  8.             var tablerows = tableobj.getElementsByTagName("tr");
  9.             if (tablerows) {
  10.                 if (sourceobj) {
  11.                     // Clone the selected row but dont erase values
  12.                     var newobj = sourceobj.cloneNode(true);
  13.                     //var newobj1 = sourceobj.nextSibling.cloneNode(true);
  14.                     newobj.style.backgroundColor = "";
  15.                 } else {
  16.                     // Clone the first row
  17.                     var newobj = tablerows[1].cloneNode(true);
  18.                     var newobj1 = tablerows[2].cloneNode(true);
  19.                     newobj.style.backgroundColor = "";
  20.                     newobj1.style.backgroundColor = "";
  21.  
  22.                     // Now erase the existing values
  23.                     inputfields = newobj.getElementsByTagName("input");
  24.                     for (var x = 0; x < inputfields.length; x++) {
  25.                         inputfields[x].value = "";
  26.                     }
  27.  
  28.                     inputfields1 = newobj1.getElementsByTagName("input");
  29.                     for (var x = 0; x < inputfields1.length; x++) {
  30.                         inputfields1[x].value = "";
  31.                     }
  32.  
  33.                     selectfields = newobj1.getElementsByTagName("select");
  34.                     for (var x = 0; x < selectfields.length; x++) {
  35.                         selectfields[x].value = "";
  36.                     }
  37.                 }
  38.                 tableobj.appendChild(newobj);
  39.                 tableobj.appendChild(newobj1);
  40.             }
  41.         }
  42.     }
Nov 24 '08 #1
1 1803
perhapscwk
123 100+
I solved it. Please ignore my post.

Thanks.
Nov 24 '08 #2

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

Similar topics

4
by: Joy | last post by:
Hi, I need to be able to to disable the Apend Row feature of the VB.NET datagrid and then enable it again. The reason is because I want to allow a user to enter as many rows in the datagrid as...
5
by: Derek Basch | last post by:
Can anyone tell me why I cant insertBefore() objects that are selected using getElementById()? <html> <head> </head> <body> <p id="heading1"></p>
4
by: Joy | last post by:
Hi, I need to be able to to disable the Apend Row feature of the VB.NET datagrid and then enable it again. The reason is because I want to allow a user to enter as many rows in the datagrid as...
2
by: Janis Papanagnou | last post by:
This is partly a repost that was maybe too buried to be seen. Sorry for that. I thought it would be an easy to be answered question, but I may be wrong... I wanted to _insert_ cloned table row...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.