<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dream House &#187; duplicate</title>
	<atom:link href="http://sajjadhossain.com/tag/duplicate/feed/" rel="self" type="application/rss+xml" />
	<link>http://sajjadhossain.com</link>
	<description>Courage to do something...</description>
	<lastBuildDate>Wed, 10 Mar 2010 05:55:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Duplicating table rows dynamically</title>
		<link>http://sajjadhossain.com/2008/01/05/duplicating-table-rows-dynamically/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://sajjadhossain.com/2008/01/05/duplicating-table-rows-dynamically/#comments</comments>
		<pubDate>Sat, 05 Jan 2008 11:47:49 +0000</pubDate>
		<dc:creator>Mohammad Sajjad Hossain</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[duplicate]]></category>
		<category><![CDATA[table rows]]></category>

		<guid isPermaLink="false">http://sajjadhossain.com/?p=9</guid>
		<description><![CDATA[For some days I was looking for a JavaScript solution for duplicating table rows. I know it is simple. But I have made a function which does this very easily. I have tested this code with IE 6.0 and FireFox 2+ browsers. Here is the JavaScript function: /** * This function duplicates a given row [...]


Related posts:<ol><li><a href='http://sajjadhossain.com/2008/01/12/10/' rel='bookmark' title='Permanent Link: Removing table rows using JavaScript'>Removing table rows using JavaScript</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>For some days I was looking for a JavaScript solution for duplicating table rows. I know it is simple. But I have made a function which does this very easily. I have tested this code with IE 6.0 and FireFox 2+ browsers.</p>
<p><strong>Here is the JavaScript function:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
* This function duplicates a given row
* Author: Mohammad Sajjad Hossain
* Email: info @t sajjadhossain.com, msh134 @t gmail.com
*
* @param targetTableId - ID of the target table
* @param targetRowIndex - index of the row which to be duplicated
* @return void
*/</span>
<span style="color: #003366; font-weight: bold;">function</span> duplicateRow<span style="color: #009900;">&#40;</span>targetTableId<span style="color: #339933;">,</span> targetRowIndex<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
     <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>targetRowIndex <span style="color: #339933;">==</span> undefined<span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
          targetRowIndex <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
&nbsp;
     <span style="color: #003366; font-weight: bold;">var</span> targetTable <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>targetTableId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #003366; font-weight: bold;">var</span> tableBody <span style="color: #339933;">=</span> targetTable.<span style="color: #660066;">tBodies</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
     <span style="color: #003366; font-weight: bold;">var</span> targetRow <span style="color: #339933;">=</span> tableBody.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;tr&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>targetRowIndex<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
     <span style="color: #003366; font-weight: bold;">var</span> newRow <span style="color: #339933;">=</span> targetRow.<span style="color: #660066;">cloneNode</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     tableBody.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>newRow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Example Code:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;javascript&quot;</span><span style="color: #339933;">&gt;</span>
     <span style="color: #003366; font-weight: bold;">function</span> duplicateRow<span style="color: #009900;">&#40;</span>targetTableId<span style="color: #339933;">,</span> targetRowIndex<span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
          <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>targetRowIndex <span style="color: #339933;">==</span> undefined<span style="color: #009900;">&#41;</span>
          <span style="color: #009900;">&#123;</span>
               targetRowIndex <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
&nbsp;
          <span style="color: #003366; font-weight: bold;">var</span> targetTable <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>targetTableId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #003366; font-weight: bold;">var</span> tableBody <span style="color: #339933;">=</span> targetTable.<span style="color: #660066;">tBodies</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
          <span style="color: #003366; font-weight: bold;">var</span> targetRow <span style="color: #339933;">=</span> tableBody.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;tr&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>targetRowIndex<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
          <span style="color: #003366; font-weight: bold;">var</span> newRow <span style="color: #339933;">=</span> targetRow.<span style="color: #660066;">cloneNode</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          tableBody.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>newRow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;table width=&quot;500&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; id=&quot;tblDuplicate&quot; border=&quot;1&quot;&gt;
     &lt;tr&gt;
          &lt;th&gt;Col1&lt;/th&gt;
          &lt;th&gt;Col2&lt;/th&gt;
          &lt;th&gt;Col3&lt;/th&gt;
          &lt;th&gt;Col4&lt;/th&gt;
     &lt;/tr&gt;
     &lt;tr&gt;
          &lt;td align=&quot;center&quot;&gt;row&lt;/td&gt;
          &lt;td align=&quot;center&quot;&gt;row&lt;/td&gt;
          &lt;td align=&quot;center&quot;&gt;row&lt;/td&gt;
          &lt;td align=&quot;center&quot;&gt;row&lt;/td&gt;
     &lt;/tr&gt;
&lt;/table&gt;
&lt;input type=&quot;button&quot; value=&quot;Duplicate Row&quot; onclick=&quot;duplicateRow('tblDuplicate', 1)&quot; /&gt;</pre></div></div>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsajjadhossain.com%2F2008%2F01%2F05%2Fduplicating-table-rows-dynamically%2F&amp;linkname=Duplicating%20table%20rows%20dynamically"><img src="http://sajjadhossain.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a> </p>

<p>Related posts:<ol><li><a href='http://sajjadhossain.com/2008/01/12/10/' rel='bookmark' title='Permanent Link: Removing table rows using JavaScript'>Removing table rows using JavaScript</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://sajjadhossain.com/2008/01/05/duplicating-table-rows-dynamically/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
