<?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; JavaScript</title>
	<atom:link href="http://sajjadhossain.com/category/javascript/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>JavaScript: String trimming and padding</title>
		<link>http://sajjadhossain.com/2008/10/31/javascript-string-trimming-and-padding/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://sajjadhossain.com/2008/10/31/javascript-string-trimming-and-padding/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 10:59:21 +0000</pubDate>
		<dc:creator>Mohammad Sajjad Hossain</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[pad]]></category>
		<category><![CDATA[padding]]></category>
		<category><![CDATA[trim]]></category>
		<category><![CDATA[trimming]]></category>

		<guid isPermaLink="false">http://sajjadhossain.com/?p=74</guid>
		<description><![CDATA[When working with JavaScript in one of my projects I needed to trim strings and pad them. I googled for a solution and many sources I have got the following codes and sharing with you. Trimming: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 //trimming space from both side [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>When working with JavaScript in one of my projects I needed to trim strings and pad them. I googled for a solution and many sources I have got the following codes and sharing with you.</p>
<p><strong>Trimming:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//trimming space from both side of the string</span>
String.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">trim</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^\s+|\s+$/g</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//trimming space from left side of the string</span>
String.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">ltrim</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^\s+/</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//trimming space from right side of the string</span>
String.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">rtrim</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\s+$/</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Using Trim Functions:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//write the code given above</span>
<span style="color: #003366; font-weight: bold;">var</span> str <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;  black  &quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a&quot;</span> <span style="color: #339933;">+</span> str.<span style="color: #660066;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;b&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #006600; font-style: italic;">//result &quot;ablackb&quot;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a&quot;</span> <span style="color: #339933;">+</span> str.<span style="color: #660066;">ltrim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;b&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">//result &quot;ablack b&quot;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a&quot;</span> <span style="color: #339933;">+</span> str.<span style="color: #660066;">rtrim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;b&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">//result &quot;a blackb&quot;</span></pre></td></tr></table></div>

<p><strong>Padding:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//pads left</span>
String.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">lpad</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>padString<span style="color: #339933;">,</span> length<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> str <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>str.<span style="color: #660066;">length</span> <span style="color: #339933;">&lt;</span> length<span style="color: #009900;">&#41;</span>
        str <span style="color: #339933;">=</span> padString <span style="color: #339933;">+</span> str<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> str<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//pads right</span>
String.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">rpad</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>padString<span style="color: #339933;">,</span> length<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> str <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>str.<span style="color: #660066;">length</span> <span style="color: #339933;">&lt;</span> length<span style="color: #009900;">&#41;</span>
        str <span style="color: #339933;">=</span> str <span style="color: #339933;">+</span> padString<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> str<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Using Padding Functions:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> str <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;5&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>str.<span style="color: #660066;">lpad</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//result &quot;00005&quot;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>str.<span style="color: #660066;">rpad</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//result &quot;50000&quot;</span></pre></td></tr></table></div>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsajjadhossain.com%2F2008%2F10%2F31%2Fjavascript-string-trimming-and-padding%2F&amp;linkname=JavaScript%3A%20String%20trimming%20and%20padding"><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>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://sajjadhossain.com/2008/10/31/javascript-string-trimming-and-padding/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Date control using JavaScript</title>
		<link>http://sajjadhossain.com/2008/03/13/date-control-using-javascript/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://sajjadhossain.com/2008/03/13/date-control-using-javascript/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 07:21:00 +0000</pubDate>
		<dc:creator>Mohammad Sajjad Hossain</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[My Works]]></category>
		<category><![CDATA[date control]]></category>
		<category><![CDATA[date field]]></category>
		<category><![CDATA[date picker]]></category>
		<category><![CDATA[form date cotrol]]></category>
		<category><![CDATA[javascript date control]]></category>
		<category><![CDATA[javascript date field]]></category>

		<guid isPermaLink="false">http://sajjadhossain.com/?p=29</guid>
		<description><![CDATA[Date control is a combination of three drop downs with month, day and year valus. It can be used as an alternative to the date picker control. Suppose a user needs to select a date before/after 10 years. At this point selecting the date with a date picker will not be easy and time consuming. [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Date control is a combination of three drop downs with month, day and year valus. It can be used as an alternative to the date picker control. Suppose a user needs to select a date before/after 10 years. At this point selecting the date with a date picker will not be easy and time consuming. So, in this situation, this control may be helpful.</p>
<p><img src="http://sajjadhossain.com/wp-content/uploads/2008/03/date_control.gif" alt="Date control" title="Date control using JavaScript" /></p>
<p>To customize you need you can configure it. Change the properties in date_control.js file.</p>
<p><strong>How to use it?</strong></p>
<p>1. Unzip the download<br />
2. Link the date_control to the page you want to use it in.<br />
3. Write this code where you want to place the control</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: #006600; font-style: italic;">// getting the date control</span>
getDateControl<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;name_of_the_field&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;name_of_the_form&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>For more details see the demo.html file included in the download.</p>
<p>I have tested the code with Internet Explorer 6 and FireFox 2.X.X and it works fine.</p>
<p>You can download a copy from here:  <a href="http://sajjadhossain.com/wp-content/uploads/2008/03/data_control.rar#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed" target="_blank" title="Date Control Download"><img src="http://sajjadhossain.com/wp-content/uploads/2008/01/download.gif" alt="Download" align="absmiddle" border="0" title="Date control using JavaScript" /></a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsajjadhossain.com%2F2008%2F03%2F13%2Fdate-control-using-javascript%2F&amp;linkname=Date%20control%20using%20JavaScript"><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>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://sajjadhossain.com/2008/03/13/date-control-using-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Removing table rows using JavaScript</title>
		<link>http://sajjadhossain.com/2008/01/12/10/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://sajjadhossain.com/2008/01/12/10/#comments</comments>
		<pubDate>Sat, 12 Jan 2008 07:36:37 +0000</pubDate>
		<dc:creator>Mohammad Sajjad Hossain</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[remove row]]></category>
		<category><![CDATA[remove table row]]></category>

		<guid isPermaLink="false">http://sajjadhossain.com/?p=10</guid>
		<description><![CDATA[In my last post I have shown how to duplicate a table row. Now if you let the user to duplicate a row then you will look for a solution to remove row dynamically using JavaScript. Use the following function to dynamically remove row from a table. This code is also tested on IE6 and [...]


Related posts:<ol><li><a href='http://sajjadhossain.com/2008/01/05/duplicating-table-rows-dynamically/' rel='bookmark' title='Permanent Link: Duplicating table rows dynamically'>Duplicating table rows dynamically</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In my last post I have shown how to duplicate a table row. Now if you let the user to duplicate a row then you will look for a solution to remove row dynamically using JavaScript. Use the following function to dynamically remove row from a table. This code is also tested on IE6 and FF2.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * Removes row of a table. Finds the table with table ID
 *
 * @param targetTableId - Table ID
 * @param targetRowIndex - index of the target row tobe removed
 * @param skipRows - Number of rows to be skipped
 */</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> removeRow<span style="color: #009900;">&#40;</span>targetTableId<span style="color: #339933;">,</span> targetRowIndex<span style="color: #339933;">,</span> skipRows<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
     <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> totalRows <span style="color: #339933;">=</span> tableBody.<span style="color: #660066;">rows</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>totalRows <span style="color: #339933;">==</span> skipRows<span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
          <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
&nbsp;
     <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: #339933;">||</span> targetRowIndex <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>   
     <span style="color: #009900;">&#123;</span>       
          targetRowIndex <span style="color: #339933;">=</span> totalRows <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>   
     <span style="color: #009900;">&#125;</span>    
    
     <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>tableBody.<span style="color: #660066;">hasChildNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>   
     <span style="color: #009900;">&#123;</span>
          tableBody.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span>tableBody.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>targetRowIndex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
     <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></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%2F12%2F10%2F&amp;linkname=Removing%20table%20rows%20using%20JavaScript"><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/05/duplicating-table-rows-dynamically/' rel='bookmark' title='Permanent Link: Duplicating table rows dynamically'>Duplicating table rows dynamically</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://sajjadhossain.com/2008/01/12/10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>
