<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;D0YBQH47eCp7ImA9WhRbFk8.&quot;"><id>tag:blogger.com,1999:blog-2885018062563133508</id><updated>2012-02-07T06:32:31.000-08:00</updated><title>JavaScript Tips</title><subtitle type="html" /><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://js-code.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://js-code.blogspot.com/" /><author><name>Eric</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>10</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/JavascriptTips" /><feedburner:info uri="javascripttips" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;C08BRXgzfip7ImA9WhZbGEs.&quot;"><id>tag:blogger.com,1999:blog-2885018062563133508.post-4385296018872282786</id><published>2011-06-23T13:44:00.000-07:00</published><updated>2011-06-23T13:44:14.686-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-23T13:44:14.686-07:00</app:edited><title>Top Rated Ajax Books</title><content type="html">&lt;style&gt;
h4 { margin-top:0; margin-left:100px; color:green}
h3 { margin-bottom:0; }
li {list-style-type:none; margin-bottom:1em;}
li a {text-decoration:none; font-weight:bold; font-size:110%}
&lt;/style&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
All the books listed here have at least a 4 star rating  and have been reviewed by at least 10 reviewers. Some reviews are included.&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.com%2FAjax-Action-Dave-Crane%2Fdp%2F1932394613%2Fsr%3D1-1%2Fqid%3D1167844379%3Fie%3DUTF8%26s%3Dbooks&amp;tag=codingtips-20&amp;linkCode=ur2&amp;camp=1789&amp;creative=9325"&gt;Ajax in Action &lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=codingtips-20&amp;amp;l=ur2&amp;amp;o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt;&lt;br /&gt;
by Dave Crane, Eric Pascarello, Darren James&lt;br /&gt;
&lt;div class=rcom&gt;&lt;strong&gt;Best AJAX Book Available Today:&lt;/strong&gt;&lt;br /&gt;
Ajax in Action by Dave Crane is the best Ajax book on the market today. With over 600 pages of content, this incredibly well-written text explains why Ajax is so powerful and how this simple programming feature (it really isn't difficult to learn at all) has changed web development forever. No longer are users and developers limited to a page reload world, as the power of this technology now has the ability to make the web work like regular applications. It's a trend that has been desired for a loooong time and boy does it ever deliver!!!&lt;br /&gt;
&lt;pre&gt;Chapter Overview:

01. Ajax background
02. Learning to use Ajax
03. Order with Ajax
04. Pages as applications
05. Serve role
06. User experience
07. Security and Ajax
08. Ajax performance
09. Dynamic double combo example
10. Type ahead example
11. Enhanced Ajax web portal
12. Live search using XSLT
13. Stand-Alone apps with Ajax
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
&lt;li&gt;&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.com%2FProfessional-Ajax-Programmer-Nicholas-Zakas%2Fdp%2F0471777781%2Fsr%3D1-2%2Fqid%3D1167844379%3Fie%3DUTF8%26s%3Dbooks&amp;tag=codingtips-20&amp;linkCode=ur2&amp;camp=1789&amp;creative=9325"&gt;Professional Ajax (Programmer to Programmer) (Paperback)&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=codingtips-20&amp;amp;l=ur2&amp;amp;o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt;&lt;br /&gt;
&lt;br /&gt;
by Nicholas C. Zakas, Jeremy McPeak, Joe Fawcett&lt;br /&gt;
&lt;div class=rcom&gt;The book does a good job academically of showing how Ajax has evolved (itself a debatable topic) and how it is used in modern-day applications. The book doesn't marry the reader to any one particular web development framework, effectively citing examples in PHP, .NET, and JavaServer Pages. Practically, the authors exhibit a proper mix of (X)HTML, CSS, JavaScript, Dynamic HTML and XmlHttpRequests, showing how the technologies are blended for developing next-gen UIs.&lt;br /&gt;
&lt;/div&gt;&lt;li&gt;&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.com%2FAJAX-PHP-Building-Responsive-Applications%2Fdp%2F1904811825%2Fsr%3D1-7%2Fqid%3D1167844379%3Fie%3DUTF8%26s%3Dbooks&amp;tag=codingtips-20&amp;linkCode=ur2&amp;camp=1789&amp;creative=9325"&gt;AJAX and PHP: Building Responsive Web Applications (Paperback)&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=codingtips-20&amp;amp;l=ur2&amp;amp;o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt;&lt;br /&gt;
by Cristian Darie, Bogdan Brinzarea, Filip Chereches-Tosa, Mihai Bucica&lt;br /&gt;
&lt;div class=rcom&gt;&lt;strong&gt;AJAX and PHP by Example:&lt;/strong&gt;This book teaches by example. The first few chapters introduce AJAX and what part PHP, Javascript and XML all play. Then the remainder of the book takes you through several example applications. The example apps are simple enough that you can easily follow. These applications include Form Validation, Chat, Suggest and Autocomplete, Charting with SVG (Scalable Vector Graphics), using grids, and Drag and Drop.&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;li&gt;&lt;br /&gt;
&lt;a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.com%2FAjax-Dummies-Computer-Tech%2Fdp%2F0471785970%2Fsr%3D1-14%2Fqid%3D1167844859%3Fie%3DUTF8%26s%3Dbooks&amp;tag=codingtips-20&amp;linkCode=ur2&amp;camp=1789&amp;creative=9325"&gt;Ajax For Dummies (For Dummies (Computer/Tech)) (Paperback)&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=codingtips-20&amp;amp;l=ur2&amp;amp;o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt;&lt;br /&gt;
by Steve Ph.D. Holzner&lt;br /&gt;
&lt;div class=rcom&gt;&lt;strong&gt;Good coverage with some unique features: &lt;/strong&gt;Ajax is obviously one of the hot web technologies these days, and now we have the Dummies title that covers it... Ajax for Dummies by Steve Holzner. While it might be easy to write this off as "just another Dummies book", I don't know that I'd be so hasty...&lt;br /&gt;
&lt;pre&gt;Contents:
Part 1 - Getting Started: Ajax 101; It's All About JavaScript
Part 2 - Programming in Ajax: Getting to Know Ajax; Ajax in Depth
Part 3 - Ajax Frameworks: Introducing Ajax Frameworks; More Powerful Ajax Frameworks; Server-Side Ajax Frameworks
Part 4 - In-Depth Ajax Power: Handling XML in Ajax Applications; Working with Cascading Style Sheets in Ajax Applications; Working with Ajax and PHP
Part 5 - The Part of Tens: Ten Ajax Design Issues You Should Know About; Ten Super-Useful Ajax Resources
&lt;/pre&gt;&lt;/div&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2885018062563133508-4385296018872282786?l=js-code.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/BSeFBrX6G5FqCOA8wciA_9p2298/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BSeFBrX6G5FqCOA8wciA_9p2298/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/BSeFBrX6G5FqCOA8wciA_9p2298/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BSeFBrX6G5FqCOA8wciA_9p2298/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavascriptTips/~4/oTudrV6IrZA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://js-code.blogspot.com/feeds/4385296018872282786/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://js-code.blogspot.com/2011/06/top-rated-ajax-books.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/4385296018872282786?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/4385296018872282786?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavascriptTips/~3/oTudrV6IrZA/top-rated-ajax-books.html" title="Top Rated Ajax Books" /><author><name>Eric</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://js-code.blogspot.com/2011/06/top-rated-ajax-books.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEcCQ3g5eCp7ImA9WhZXFk0.&quot;"><id>tag:blogger.com,1999:blog-2885018062563133508.post-2004252283009427070</id><published>2011-05-02T13:19:00.000-07:00</published><updated>2011-05-05T06:27:42.620-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-05T06:27:42.620-07:00</app:edited><title>Highlight HTML Table Rows with JavaScript</title><content type="html">&lt;h3 style="margin-top: 50px;"&gt;Highlight Table Rows on Mouseover&lt;/h3&gt;&lt;br /&gt;
To highlight whole rows, use the following function:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;function hiLiteRows(){
 var table = document.getElementById('myTable2');
 for (var i=0;i &amp;lt; table.rows.length;i++)
 {
  table.rows[i].onmouseover = function () {
   this.origColor=this.style.backgroundColor;
   this.style.backgroundColor='#BCD4EC';
  }
  table.rows[i].onmouseout = function () {this.style.backgroundColor=this.origColor;}
 }
}
&lt;/pre&gt;We use a &lt;i&gt;rows&lt;/i&gt; array to get access to table rows. The basic principle is as follows: the original background color is saved in a custom property of a row object to be restored on the mouseout event. The &lt;i&gt;this &lt;/i&gt;keyword here refers to the &lt;b&gt;row &lt;/b&gt;object.&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style="margin-top: 50px;"&gt;Highlight TableRows on Click Event&lt;/h3&gt;&lt;br /&gt;
To highlight table rows on the click event, we modify the previous function:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;function hiLiteRowsClick(){
 var table = document.getElementById('myTable3');
 for (var i=0;i &amp;lt; table.rows.length;i++){
  table.rows[i].onclick= function () {
   if(!this.hilite){
    this.origColor=this.style.backgroundColor;
    this.style.backgroundColor='#BCD4EC';
    this.hilite = true;
   }
   else{
    this.style.backgroundColor=this.origColor;
    this.hilite = false;
   }
    }
 }
}
&lt;/pre&gt;&lt;br /&gt;
Instead of the &lt;i&gt;mouseover&lt;/i&gt; event, we use the &lt;i&gt;onclick&lt;/i&gt; event to call the anonymous function.&lt;br /&gt;
The function will change the background color when a row is clicked for the first time. When a row is clicked again, the original color is restored. To keep track of the click sequence the function uses a custom property called &lt;strong&gt;hilite&lt;/strong&gt;.&lt;br /&gt;
This property is set to &lt;i&gt;true &lt;/i&gt;on the first click and set to &lt;i&gt;false&lt;/i&gt; on the second one.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2885018062563133508-2004252283009427070?l=js-code.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/RXkxQUu4XGYuuUO_oH27HuMOaaU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/RXkxQUu4XGYuuUO_oH27HuMOaaU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/RXkxQUu4XGYuuUO_oH27HuMOaaU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/RXkxQUu4XGYuuUO_oH27HuMOaaU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavascriptTips/~4/EiuCacRy_d0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://js-code.blogspot.com/feeds/2004252283009427070/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://js-code.blogspot.com/2011/05/highlight-table-rows.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/2004252283009427070?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/2004252283009427070?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavascriptTips/~3/EiuCacRy_d0/highlight-table-rows.html" title="Highlight HTML Table Rows with JavaScript" /><author><name>Eric</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://js-code.blogspot.com/2011/05/highlight-table-rows.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUYESXY_eCp7ImA9WhZXE0s.&quot;"><id>tag:blogger.com,1999:blog-2885018062563133508.post-7937434368323064632</id><published>2011-05-02T13:11:00.000-07:00</published><updated>2011-05-02T13:11:48.840-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-02T13:11:48.840-07:00</app:edited><title>A Simple Way to Highlight Table Cells with JavaScript</title><content type="html">&lt;p&gt;Here is a simple script to highlight table cells on the MouseOver event. The script restores the original color&lt;br /&gt;
on the MouseOut event.&lt;br /&gt;
&lt;br /&gt;
&lt;TABLE id='myTable' width=40% align='center' border=1&gt;&lt;TR&gt;
&lt;TD&gt;One&lt;/TD&gt;
&lt;TD&gt;One&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Two&lt;/TD&gt;
&lt;TD&gt;Two&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Three&lt;/TD&gt;
&lt;TD&gt;Three&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Four&lt;/TD&gt;
&lt;TD&gt;Four&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TABLE&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;function hiLiteCells(){
 var table = document.getElementById('myTable');
 var x = table.getElementsByTagName('td');
 for (var i=0;i&amp;lt;x.length;i++)
 {
  x[i].onmouseover = function (){
   this.origColor=this.style.backgroundColor;
   this.style.backgroundColor='#BCD4EC';
  }
  x[i].onmouseout = function () {
   this.style.backgroundColor=this.origColor;
  }
 }
}
&lt;/pre&gt;&lt;p&gt;Here is what's happening in the function. First, we get a reference to the table element.&lt;br /&gt;
&lt;pre&gt;var table = document.getElementById('myTable');
&lt;/pre&gt;Then we get a reference to all the cells in the particular table.&lt;br /&gt;
&lt;pre&gt;var x = table.getElementsByTagName('td');
&lt;/pre&gt;Then we attach anonymous functions to the mouseover and mouseout events on the cells. The mouseover function stores&lt;br /&gt;
the cell's original color in a variable local to the cell object represented by the &lt;b&gt;&lt;i&gt;this&lt;/i&gt;&lt;/b&gt; keyword.&lt;br /&gt;
&lt;pre&gt;var x = document.getElementsByTagName('tr');
&lt;/pre&gt;&lt;p&gt;Don't forget to substitute your own table id for the &lt;i&gt;myTable&lt;/i&gt; table id.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2885018062563133508-7937434368323064632?l=js-code.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/8QciFYzpAUajY1wVRWtRzKE7UKc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8QciFYzpAUajY1wVRWtRzKE7UKc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/8QciFYzpAUajY1wVRWtRzKE7UKc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8QciFYzpAUajY1wVRWtRzKE7UKc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavascriptTips/~4/S8U-YwFSx6U" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://js-code.blogspot.com/feeds/7937434368323064632/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://js-code.blogspot.com/2011/05/simple-way-to-highlight-table-cells.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/7937434368323064632?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/7937434368323064632?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavascriptTips/~3/S8U-YwFSx6U/simple-way-to-highlight-table-cells.html" title="A Simple Way to Highlight Table Cells with JavaScript" /><author><name>Eric</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://js-code.blogspot.com/2011/05/simple-way-to-highlight-table-cells.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEMASHgzeyp7ImA9Wx9SGUQ.&quot;"><id>tag:blogger.com,1999:blog-2885018062563133508.post-8026086644346932303</id><published>2010-12-10T06:47:00.000-08:00</published><updated>2010-12-10T06:47:29.683-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-10T06:47:29.683-08:00</app:edited><title>Insert Backslash Before a Double Quote</title><content type="html">Sometimes, you need to dynamically write html text from JavaScript. If the text contains a combination of single and double quotes, you may run into problems. Here is a simple function to avoid those problems.   &lt;br /&gt;
&lt;pre&gt;function insertBackslashBeforeDoubleQuote(str){
 var reg = /"/g;
 var newstr = '\\"';
 return str.replace(reg,newstr);
}&lt;/pre&gt;As you see, the function uses a RegExp object on the first line to look for a double quote: &lt;pre&gt;reg = /"/g;
 &lt;/pre&gt;The second line defines our replacement string - &lt;b&gt;\" &lt;/b&gt;&lt;br /&gt;
The backslash in front of the quote has to be escaped with another backslash. &lt;pre&gt;newstr = '\\"';&lt;/pre&gt;The last line searches the string and if a double quote is found it is replaced by our &lt;i&gt;newstr&lt;/i&gt; pattern. &lt;pre&gt;return str.replace(reg,newstr);&lt;/pre&gt;Here is a similar function that inserts a backslash before a &lt;b&gt;single&lt;/b&gt; quote if it is contained in the string argument. &lt;pre&gt;function insertBackslashBeforeSingleQuote(str){
 var reg = /'/g;
 var newstr = "\\'"
 return str.replace(reg,newstr);
}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2885018062563133508-8026086644346932303?l=js-code.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/pxFift5JwBetGLweV10b-_hNwUU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pxFift5JwBetGLweV10b-_hNwUU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/pxFift5JwBetGLweV10b-_hNwUU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pxFift5JwBetGLweV10b-_hNwUU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavascriptTips/~4/rsOsyMzoKiA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://js-code.blogspot.com/feeds/8026086644346932303/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://js-code.blogspot.com/2010/12/insert-backslash-before-double-quote.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/8026086644346932303?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/8026086644346932303?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavascriptTips/~3/rsOsyMzoKiA/insert-backslash-before-double-quote.html" title="Insert Backslash Before a Double Quote" /><author><name>Eric</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://js-code.blogspot.com/2010/12/insert-backslash-before-double-quote.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0QGQX0_fyp7ImA9Wx9SF0k.&quot;"><id>tag:blogger.com,1999:blog-2885018062563133508.post-3742144016502440050</id><published>2010-11-17T06:04:00.000-08:00</published><updated>2010-12-07T10:08:40.347-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-07T10:08:40.347-08:00</app:edited><title>"Event is Not Defined" Error in Firefox</title><content type="html">This error may occur when you try to attach a &lt;b&gt;JavaScript &lt;/b&gt;function dynamically to page elements and pass an event to the function. An example:&lt;br /&gt;
&lt;div style="background: none repeat scroll 0% 0% white; color: black; font-family: Consolas; font-size: 11pt; padding: 8px;"&gt;&lt;div style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;var&lt;/span&gt; inputs = document.getElementsByTagName(&lt;span style="color: #a31515;"&gt;'input'&lt;/span&gt;);&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;for&lt;/span&gt; (&lt;span style="color: blue;"&gt;var&lt;/span&gt; i = 0; i &amp;lt; inputs.length; i++) {&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt; (inputs[i].type == &lt;span style="color: #a31515;"&gt;'text'&lt;/span&gt;) {&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; inputs[i].onkeypress = &lt;span style="color: blue;"&gt;function&lt;/span&gt;() { &lt;span style="color: blue;"&gt;return&lt;/span&gt; isNumericKey(event); }&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;&lt;div style="margin: 0px;"&gt;};&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
Here is a listing of the validation &lt;b&gt;function&lt;/b&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style="background: none repeat scroll 0% 0% white; color: black; font-family: Consolas; font-size: 11pt; padding: 8px;"&gt;&lt;div style="margin: 0px;"&gt;&lt;span style="color: green;"&gt;/* Numeric Validation */&lt;/span&gt;&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;function&lt;/span&gt; isNumericKey(evt) {&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;var&lt;/span&gt; charCode = (evt.which) ? evt.which : event.keyCode;&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt; (charCode &amp;gt;= 48 &amp;amp;&amp;amp; charCode &amp;lt;= 57 || charCode == 46) {&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: blue;"&gt;true&lt;/span&gt;;&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;else&lt;/span&gt; {&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; &lt;span style="color: blue;"&gt;false&lt;/span&gt;;&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;&lt;div style="margin: 0px;"&gt;} &lt;/div&gt;&lt;div style="margin: 0px;"&gt;&amp;nbsp; &lt;/div&gt;&lt;/div&gt;This code will work perfectly in IE and it won't allow users to type any other characters than numeric. However, in Firefox, it will throw an error: "event is not defined".&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;First solution:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Check whether the event is defined in Firefox and attach a reference to the validation function. &lt;br /&gt;
&lt;br /&gt;
&lt;div style="background: none repeat scroll 0% 0% white; color: black; font-family: Consolas; font-size: 11pt; padding: 8px;"&gt;&lt;div style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;if&lt;/span&gt; (&lt;span style="color: blue;"&gt;typeof&lt;/span&gt; (event) == &lt;span style="color: #a31515;"&gt;"undefined"&lt;/span&gt;)&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; inputs[i].onkeypress = isNegativeNumericKey;&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;else&lt;/span&gt;&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; inputs[i].onkeypress = &lt;span style="color: blue;"&gt;function&lt;/span&gt;() { &lt;span style="color: blue;"&gt;return&lt;/span&gt; isNumericKey(event);}&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
In this case, the event is a global variable that does not exist in Firefox. We could have rewritten the type check as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: blue;"&gt;if&lt;/span&gt; (&lt;span style="color: blue;"&gt;typeof&lt;/span&gt; (window.event) == &lt;span style="color: #a31515;"&gt;"undefined"&lt;/span&gt;) ...&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Second solution:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Use the following version of the function call in Firefox by passing the event parameter to the function that handles the keypress event:&lt;br /&gt;
&lt;div style="background: none repeat scroll 0% 0% white; color: black; font-family: Consolas; font-size: 11pt; padding: 8px;"&gt;&lt;br /&gt;
inputs[i].onkeypress = &lt;span style="color: blue;"&gt;function&lt;/span&gt;(event) { &lt;span style="color: blue;"&gt;return&lt;/span&gt; isNumericKey(event);}&lt;/div&gt;&lt;br /&gt;
But this would not work in IE.&amp;nbsp; The solution: &lt;a href="http://stackoverflow.com/questions/3774468/event-is-undefined-in-ie-works-in-firefox"&gt;normalize the Event interface&lt;/a&gt; in the function body:&lt;br /&gt;
&lt;br /&gt;
&lt;div style="background: none repeat scroll 0% 0% white; color: black; font-family: Consolas; font-size: 11pt; padding: 8px;"&gt;&lt;div style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;function&lt;/span&gt;(event) {&amp;nbsp; &lt;/div&gt;&lt;div style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp; &lt;b&gt;event = event || window.event;&lt;/b&gt;&lt;/div&gt;&lt;div style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp; return&lt;/span&gt; isNumericKey(event);&amp;nbsp;&lt;/div&gt;&lt;div style="margin: 0px;"&gt;}&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2885018062563133508-3742144016502440050?l=js-code.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/9VwJNAvDaLkjsWGnsIc2DkpHqfM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9VwJNAvDaLkjsWGnsIc2DkpHqfM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/9VwJNAvDaLkjsWGnsIc2DkpHqfM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9VwJNAvDaLkjsWGnsIc2DkpHqfM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavascriptTips/~4/GUFTaFSkrf8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://js-code.blogspot.com/feeds/3742144016502440050/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://js-code.blogspot.com/2010/11/event-is-not-defined-error-in-firefox.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/3742144016502440050?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/3742144016502440050?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavascriptTips/~3/GUFTaFSkrf8/event-is-not-defined-error-in-firefox.html" title="&quot;Event is Not Defined&quot; Error in Firefox" /><author><name>Eric</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://js-code.blogspot.com/2010/11/event-is-not-defined-error-in-firefox.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ak4ASH87eCp7ImA9WhZXE0s.&quot;"><id>tag:blogger.com,1999:blog-2885018062563133508.post-5761048214960950078</id><published>2009-12-09T13:00:00.000-08:00</published><updated>2011-05-02T13:42:29.100-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-02T13:42:29.100-07:00</app:edited><title>A Graph in Table Without Image</title><content type="html">Here is a simple script to add a graph to a table cell. &lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-xUPcnCN_oic/Tb8XGrZn5dI/AAAAAAAAAiw/BIwAWjqCbV0/s1600/graph.jpg" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="89" width="238" src="http://3.bp.blogspot.com/-xUPcnCN_oic/Tb8XGrZn5dI/AAAAAAAAAiw/BIwAWjqCbV0/s320/graph.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each table row consists of 2 cells. The first cell contains a numeric value. For each row, in the second cell, the script creates a span with a width equal to the value in the first cell:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
&lt;pre&gt;var tbl = document.getElementById('tbl');
for(var i=0; i&amp;lt;tbl.rows.length; i++){
var val = tbl.rows[i].cells[0].innerHTML;
var span = document.createElement("span");
span.style.width = val/100*100;
span.className = "graph";
var cell =tbl.rows[i].cells[1];
cell.style.textAlign= 'left';
cell.appendChild(span);
}
&lt;/pre&gt;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
It assumes you set a style for a "graph" class. Alternatively, you could set background color in the script. Also, the maximum span width of 100 is assumed.&lt;br /&gt;
&lt;br /&gt;
A side note: to create a rounded span in Firefox, use the following style for the "graph" class:&lt;br /&gt;
&lt;span style="font-style:italic;"&gt;-moz-border-radius: 10px;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2885018062563133508-5761048214960950078?l=js-code.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/DZdTTCZFgDWn73T2Mt_RildMATE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/DZdTTCZFgDWn73T2Mt_RildMATE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/DZdTTCZFgDWn73T2Mt_RildMATE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/DZdTTCZFgDWn73T2Mt_RildMATE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavascriptTips/~4/pXzZAZEsGX8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://js-code.blogspot.com/feeds/5761048214960950078/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://js-code.blogspot.com/2009/12/here-is-simple-script-to-add-graph-to.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/5761048214960950078?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/5761048214960950078?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavascriptTips/~3/pXzZAZEsGX8/here-is-simple-script-to-add-graph-to.html" title="A Graph in Table Without Image" /><author><name>Eric</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-xUPcnCN_oic/Tb8XGrZn5dI/AAAAAAAAAiw/BIwAWjqCbV0/s72-c/graph.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://js-code.blogspot.com/2009/12/here-is-simple-script-to-add-graph-to.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C08CQng4fSp7ImA9WxJVFUs.&quot;"><id>tag:blogger.com,1999:blog-2885018062563133508.post-344004201930319155</id><published>2009-05-22T13:19:00.000-07:00</published><updated>2009-07-02T12:11:03.635-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-07-02T12:11:03.635-07:00</app:edited><title>A Progress Bar Example</title><content type="html">&lt;pre  style="color:white;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;div id&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;pbar&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; style&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;width:400px&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;                &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;span id&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;pbar_internal&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; style&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;width:0px;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;span&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;        &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;/&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;div&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;&lt;br /&gt;Create an array &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;with&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; numbers from &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; to &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;. The array will provide data &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; our progress bar.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-style: italic;"&gt;var&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt; arr &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt; [&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;3&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;4&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;,&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="font-style: italic;"&gt;];&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The initial array count is set at &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-style: italic;"&gt;var&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt; curIndex &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="font-style: italic;"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create variables holding references to the div and span elements:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-style: italic;"&gt;var&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt; div &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt; document.getElementById(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;pbar&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-style: italic;"&gt;var&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt; span &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt; document.getElementById(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;pbar_internal&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="font-style: italic;"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Save the div width &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; a variable:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-style: italic;"&gt;var&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt; parWidth &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="font-style: italic;"&gt; parseInt(div.style.width);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create a &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; that will update the span width depending on the value of&lt;br /&gt;the current array count:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-style: italic;"&gt;function&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt; showBar ()&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-style: italic;"&gt;if&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;(curIndex &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;&lt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt; arr.length){ &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-style: italic;"&gt;var&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt; spanWidth &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt; parseInt(parWidth&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;/&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;arr.length &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;*&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt; curIndex);&lt;br /&gt;span.style.width &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt; spanWidth ; } &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-style: italic;"&gt;&lt;br /&gt;else&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="font-style: italic;"&gt; clearInterval(id); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;} &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To launch &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;, we will use a JavaScript &lt;span style="font-weight: bold;"&gt;setInterval &lt;/span&gt;method.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255); font-style: italic;"&gt;var&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt; id &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt; setInterval ( showBar, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;1000&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="font-style: italic;"&gt; );&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;What we &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;do&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; here is we tell the browser to run the showBar &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; every second.&lt;br /&gt;When the current array counter reaches the end of the array,&lt;br /&gt;we cancel the setInterval method by calling the clearInterval method.&lt;br /&gt;&lt;br /&gt;We are almost done now. However, the code above will work only &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; IE&lt;br /&gt;unless we use a specific span style &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; Firefox and Opera. Here it is:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;span {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;display:&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;-&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;moz&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;-&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;inline&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;-&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;box; &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0); font-style: italic;"&gt;/*&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0); font-style: italic;"&gt; Gecko proprietary &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0); font-style: italic;"&gt;*/&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;&lt;br /&gt;display:inline&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;-&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;block; &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0); font-style: italic;"&gt;/*&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0); font-style: italic;"&gt; supported by Opera and ? &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0); font-style: italic;"&gt;*/&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;&lt;br /&gt;width:&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;25&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;%&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;;height:1em; &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0); font-style: italic;"&gt;/*&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0); font-style: italic;"&gt; width and height required &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0); font-style: italic;"&gt;*/&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;&lt;br /&gt;vertical&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;-&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;align:top; &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0); font-style: italic;"&gt;/*&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0); font-style: italic;"&gt; Gecko needs this &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0); font-style: italic;"&gt;*/&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0); font-style: italic;"&gt;&lt;br /&gt;} &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0); font-style: italic;"&gt;/*&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0); font-style: italic;"&gt; IE, Opera &amp;amp; Gecko slight diff &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0); font-style: italic;"&gt;*/&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;&lt;br /&gt;I&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;ll try to post a live demo later on.&lt;/span&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2885018062563133508-344004201930319155?l=js-code.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/8icCVE3rEf7_q0DiJwrTUYxrQg4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8icCVE3rEf7_q0DiJwrTUYxrQg4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/8icCVE3rEf7_q0DiJwrTUYxrQg4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8icCVE3rEf7_q0DiJwrTUYxrQg4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavascriptTips/~4/9ndbWst4_9w" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://js-code.blogspot.com/feeds/344004201930319155/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://js-code.blogspot.com/2009/05/progress-bar-example.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/344004201930319155?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/344004201930319155?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavascriptTips/~3/9ndbWst4_9w/progress-bar-example.html" title="A Progress Bar Example" /><author><name>Eric</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://js-code.blogspot.com/2009/05/progress-bar-example.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUICRng8eyp7ImA9WxJQEE8.&quot;"><id>tag:blogger.com,1999:blog-2885018062563133508.post-3224387101668235009</id><published>2009-05-20T06:08:00.000-07:00</published><updated>2009-05-22T13:19:27.673-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-05-22T13:19:27.673-07:00</app:edited><title>Enumerate Array or Object</title><content type="html">This is how you could enumerate properties  of a JavaScript array:&lt;br /&gt;&lt;br /&gt;var arr = ['a', 'b', 'c'];&lt;br /&gt;&lt;br /&gt;for (var prop in arr)&lt;br /&gt;  alert (prop + ":"+ arr[prop]);&lt;br /&gt;&lt;br /&gt;Result:&lt;br /&gt;   0:a&lt;br /&gt;   1:b&lt;br /&gt;   2:c&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2885018062563133508-3224387101668235009?l=js-code.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/j1vl3vlHx0gLSBnqs_K0FkicqTE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/j1vl3vlHx0gLSBnqs_K0FkicqTE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/j1vl3vlHx0gLSBnqs_K0FkicqTE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/j1vl3vlHx0gLSBnqs_K0FkicqTE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavascriptTips/~4/wuGxKjx8Yt8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://js-code.blogspot.com/feeds/3224387101668235009/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://js-code.blogspot.com/2009/05/enumerate-through-array-object.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/3224387101668235009?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/3224387101668235009?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavascriptTips/~3/wuGxKjx8Yt8/enumerate-through-array-object.html" title="Enumerate Array or Object" /><author><name>Eric</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://js-code.blogspot.com/2009/05/enumerate-through-array-object.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0QBRXY_fip7ImA9Wx9SF0k.&quot;"><id>tag:blogger.com,1999:blog-2885018062563133508.post-1612136084042548487</id><published>2009-03-26T13:38:00.000-07:00</published><updated>2010-12-07T10:09:14.846-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-12-07T10:09:14.846-08:00</app:edited><title>Expand/Collapse Rows Dynamically with DOM and JavaScript</title><content type="html">Suppose, you have a table structured as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_z3bqutNd8ec/ScvpgdM_gmI/AAAAAAAAAWs/4b3SK5NLQ8s/s1600-h/table1.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5317600528845210210" src="http://2.bp.blogspot.com/_z3bqutNd8ec/ScvpgdM_gmI/AAAAAAAAAWs/4b3SK5NLQ8s/s320/table1.JPG" style="cursor: pointer; float: none; height: 196px; margin: 0pt 0pt 10px 10px; width: 256px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
The first line for a new month is always a total of the project amounts. This structure comes from an sql query, using the Oracle GROUP BY CUBE clause. Would not it be nice to be able to see only the rows with intermediate totals, expanding this or that month if necessary.&lt;br /&gt;
&lt;a href="http://1.bp.blogspot.com/_z3bqutNd8ec/ScvpwZSOZiI/AAAAAAAAAW0/UArOSqnvKgw/s1600-h/table2.JPG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5317600802671322658" src="http://1.bp.blogspot.com/_z3bqutNd8ec/ScvpwZSOZiI/AAAAAAAAAW0/UArOSqnvKgw/s320/table2.JPG" style="cursor: pointer; float: left; height: 139px; margin: 0pt 10px 10px 0pt; width: 320px;" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is a set of &lt;b&gt;JavaScript &lt;/b&gt;functions that collapses and expands table rows:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="color: blue; font-weight: bold;"&gt;var&lt;/span&gt; tbl&lt;span style="color: black;"&gt;;&lt;/span&gt;

&lt;span style="color: blue; font-weight: bold;"&gt;function&lt;/span&gt; &lt;span style="color: black;"&gt;getParent&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;el&lt;span style="color: black;"&gt;,&lt;/span&gt; pTagName&lt;span style="color: black;"&gt;) {&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: black;"&gt;(&lt;/span&gt;el &lt;span style="color: black;"&gt;==&lt;/span&gt; &lt;span style="color: blue; font-weight: bold;"&gt;null&lt;/span&gt;&lt;span style="color: black;"&gt;)&lt;/span&gt; &lt;span style="color: blue; font-weight: bold;"&gt;return null&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;else if&lt;/span&gt; &lt;span style="color: black;"&gt;(&lt;/span&gt;el&lt;span style="color: black;"&gt;.&lt;/span&gt;nodeType &lt;span style="color: black;"&gt;==&lt;/span&gt; &lt;span style="color: black;"&gt;1&lt;/span&gt; &lt;span style="color: black;"&gt;&amp;amp;&amp;amp;&lt;/span&gt; el&lt;span style="color: black;"&gt;.&lt;/span&gt;tagName&lt;span style="color: black;"&gt;.&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;toLowerCase&lt;/span&gt;&lt;span style="color: black;"&gt;() ==&lt;/span&gt; pTagName&lt;span style="color: black;"&gt;.&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;toLowerCase&lt;/span&gt;&lt;span style="color: black;"&gt;())&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;return&lt;/span&gt; el&lt;span style="color: black;"&gt;;&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;else&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: black;"&gt;getParent&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;el&lt;span style="color: black;"&gt;.&lt;/span&gt;parentNode&lt;span style="color: black;"&gt;,&lt;/span&gt; pTagName&lt;span style="color: black;"&gt;);&lt;/span&gt;
&lt;span style="color: black;"&gt;}&lt;/span&gt;


&lt;span style="color: blue; font-weight: bold;"&gt;function&lt;/span&gt; &lt;span style="color: black;"&gt;toggleSection&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;lnk&lt;span style="color: black;"&gt;){&lt;/span&gt;

&lt;span style="color: blue; font-weight: bold;"&gt;var&lt;/span&gt; td &lt;span style="color: black;"&gt;=&lt;/span&gt; lnk&lt;span style="color: black;"&gt;.&lt;/span&gt;parentNode&lt;span style="color: black;"&gt;;&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;var&lt;/span&gt; table &lt;span style="color: black;"&gt;=&lt;/span&gt; &lt;span style="color: black;"&gt;getParent&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;td&lt;span style="color: black;"&gt;,&lt;/span&gt;&lt;span style="color: black;"&gt;'TABLE'&lt;/span&gt;&lt;span style="color: black;"&gt;);&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;var&lt;/span&gt; len &lt;span style="color: black;"&gt;=&lt;/span&gt; table&lt;span style="color: black;"&gt;.&lt;/span&gt;rows&lt;span style="color: black;"&gt;.&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;length&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;var&lt;/span&gt; tr &lt;span style="color: black;"&gt;=&lt;/span&gt; &lt;span style="color: black;"&gt;getParent&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;td&lt;span style="color: black;"&gt;,&lt;/span&gt; &lt;span style="color: black;"&gt;'tr'&lt;/span&gt;&lt;span style="color: black;"&gt;);&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;var&lt;/span&gt; rowIndex &lt;span style="color: black;"&gt;=&lt;/span&gt; tr&lt;span style="color: black;"&gt;.&lt;/span&gt;rowIndex&lt;span style="color: black;"&gt;;&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;var&lt;/span&gt; rowHead&lt;span style="color: black;"&gt;=&lt;/span&gt;table&lt;span style="color: black;"&gt;.&lt;/span&gt;rows&lt;span style="color: black;"&gt;[&lt;/span&gt;rowIndex&lt;span style="color: black;"&gt;].&lt;/span&gt;cells&lt;span style="color: black;"&gt;[&lt;/span&gt;&lt;span style="color: black;"&gt;1&lt;/span&gt;&lt;span style="color: black;"&gt;].&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;innerHTML&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt;

lnk&lt;span style="color: black;"&gt;.&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;innerHTML&lt;/span&gt; &lt;span style="color: black;"&gt;=(&lt;/span&gt;lnk&lt;span style="color: black;"&gt;.&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;innerHTML&lt;/span&gt; &lt;span style="color: black;"&gt;==&lt;/span&gt; &lt;span style="color: black;"&gt;"+"&lt;/span&gt;&lt;span style="color: black;"&gt;)&lt;/span&gt;?&lt;span style="color: black;"&gt;"-"&lt;/span&gt;&lt;span style="color: black;"&gt;:&lt;/span&gt;&lt;span style="color: black;"&gt;"+"&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt;
vStyle &lt;span style="color: black;"&gt;=(&lt;/span&gt;tbl&lt;span style="color: black;"&gt;.&lt;/span&gt;rows&lt;span style="color: black;"&gt;[&lt;/span&gt;rowIndex&lt;span style="color: black;"&gt;+&lt;/span&gt;&lt;span style="color: black;"&gt;1&lt;/span&gt;&lt;span style="color: black;"&gt;].&lt;/span&gt;style&lt;span style="color: black;"&gt;.&lt;/span&gt;display&lt;span style="color: black;"&gt;==&lt;/span&gt;&lt;span style="color: black;"&gt;'none'&lt;/span&gt;&lt;span style="color: black;"&gt;)&lt;/span&gt;?&lt;span style="color: black;"&gt;''&lt;/span&gt;&lt;span style="color: black;"&gt;:&lt;/span&gt;&lt;span style="color: black;"&gt;'none'&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt;

&lt;span style="color: blue; font-weight: bold;"&gt;for&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;var&lt;/span&gt; i &lt;span style="color: black;"&gt;=&lt;/span&gt; rowIndex&lt;span style="color: black;"&gt;+&lt;/span&gt;&lt;span style="color: black;"&gt;1&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt; i &lt;span style="color: black;"&gt;&amp;lt;&lt;/span&gt; len&lt;span style="color: black;"&gt;;&lt;/span&gt;i&lt;span style="color: black;"&gt;++){&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: black;"&gt;(&lt;/span&gt;table&lt;span style="color: black;"&gt;.&lt;/span&gt;rows&lt;span style="color: black;"&gt;[&lt;/span&gt;i&lt;span style="color: black;"&gt;].&lt;/span&gt;cells&lt;span style="color: black;"&gt;[&lt;/span&gt;&lt;span style="color: black;"&gt;1&lt;/span&gt;&lt;span style="color: black;"&gt;].&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;innerHTML&lt;/span&gt;&lt;span style="color: black;"&gt;==&lt;/span&gt;rowHead&lt;span style="color: black;"&gt;){&lt;/span&gt;
table&lt;span style="color: black;"&gt;.&lt;/span&gt;rows&lt;span style="color: black;"&gt;[&lt;/span&gt;i&lt;span style="color: black;"&gt;].&lt;/span&gt;style&lt;span style="color: black;"&gt;.&lt;/span&gt;display&lt;span style="color: black;"&gt;=&lt;/span&gt; vStyle&lt;span style="color: black;"&gt;;&lt;/span&gt;
table&lt;span style="color: black;"&gt;.&lt;/span&gt;rows&lt;span style="color: black;"&gt;[&lt;/span&gt;i&lt;span style="color: black;"&gt;].&lt;/span&gt;cells&lt;span style="color: black;"&gt;[&lt;/span&gt;&lt;span style="color: black;"&gt;1&lt;/span&gt;&lt;span style="color: black;"&gt;].&lt;/span&gt;style&lt;span style="color: black;"&gt;.&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;visibility&lt;/span&gt;&lt;span style="color: black;"&gt;=&lt;/span&gt;&lt;span style="color: black;"&gt;"hidden"&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt;
&lt;span style="color: black;"&gt;}&lt;/span&gt;
&lt;span style="color: black;"&gt;}&lt;/span&gt;
&lt;span style="color: black;"&gt;}&lt;/span&gt;

&lt;span style="color: blue; font-weight: bold;"&gt;function&lt;/span&gt; &lt;span style="color: black;"&gt;collapseRows&lt;/span&gt;&lt;span style="color: black;"&gt;(){&lt;/span&gt;
tables &lt;span style="color: black;"&gt;=&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;document&lt;/span&gt;&lt;span style="color: black;"&gt;.&lt;/span&gt;&lt;span style="color: black;"&gt;getElementsByTagName&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;&lt;span style="color: black;"&gt;"table"&lt;/span&gt;&lt;span style="color: black;"&gt;);&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;for&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;i &lt;span style="color: black;"&gt;=&lt;/span&gt;&lt;span style="color: black;"&gt;0&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt; i &lt;span style="color: black;"&gt;&amp;lt;&lt;/span&gt; tables&lt;span style="color: black;"&gt;.&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;length&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt;i&lt;span style="color: black;"&gt;++){&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;if&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;tables&lt;span style="color: black;"&gt;[&lt;/span&gt;i&lt;span style="color: black;"&gt;].&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;className&lt;/span&gt;&lt;span style="color: black;"&gt;.&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;indexOf&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;&lt;span style="color: black;"&gt;"expandable"&lt;/span&gt;&lt;span style="color: black;"&gt;) != -&lt;/span&gt;&lt;span style="color: black;"&gt;1&lt;/span&gt;&lt;span style="color: black;"&gt;)&lt;/span&gt;
tbl &lt;span style="color: black;"&gt;=&lt;/span&gt;tables&lt;span style="color: black;"&gt;[&lt;/span&gt;i&lt;span style="color: black;"&gt;];&lt;/span&gt;
&lt;span style="color: black;"&gt;}&lt;/span&gt;

&lt;span style="color: blue; font-weight: bold;"&gt;if&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;typeof&lt;/span&gt; tbl&lt;span style="color: black;"&gt;==&lt;/span&gt;&lt;span style="color: black;"&gt;'undefined'&lt;/span&gt;&lt;span style="color: black;"&gt;){&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;alert&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;&lt;span style="color: black;"&gt;"Could not find a table of expandable class"&lt;/span&gt;&lt;span style="color: black;"&gt;);&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;return&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt;
&lt;span style="color: black;"&gt;}&lt;/span&gt;

&lt;span style="color: green; font-style: italic;"&gt;//assume the first row is headings and the first column is empty&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;var&lt;/span&gt; len &lt;span style="color: black;"&gt;=&lt;/span&gt; tbl&lt;span style="color: black;"&gt;.&lt;/span&gt;rows&lt;span style="color: black;"&gt;.&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;length&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;var&lt;/span&gt; link &lt;span style="color: black;"&gt;=&lt;/span&gt; &lt;span style="color: black;"&gt;'&amp;lt;a href="#" onclick="toggleSection(this);return false;"&amp;gt;+ &amp;lt;/a&amp;gt; '&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt;

&lt;span style="color: blue; font-weight: bold;"&gt;var&lt;/span&gt; rowHead &lt;span style="color: black;"&gt;=&lt;/span&gt; tbl&lt;span style="color: black;"&gt;.&lt;/span&gt;rows&lt;span style="color: black;"&gt;[&lt;/span&gt;&lt;span style="color: black;"&gt;1&lt;/span&gt;&lt;span style="color: black;"&gt;].&lt;/span&gt;cells&lt;span style="color: black;"&gt;[&lt;/span&gt;&lt;span style="color: black;"&gt;1&lt;/span&gt;&lt;span style="color: black;"&gt;].&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;innerHTML&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt;

&lt;span style="color: blue; font-weight: bold;"&gt;for&lt;/span&gt; &lt;span style="color: black;"&gt;(&lt;/span&gt;j&lt;span style="color: black;"&gt;=&lt;/span&gt;&lt;span style="color: black;"&gt;1&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt; j &lt;span style="color: black;"&gt;&amp;lt;&lt;/span&gt; len&lt;span style="color: black;"&gt;;&lt;/span&gt;j&lt;span style="color: black;"&gt;++){&lt;/span&gt;
&lt;span style="color: green; font-style: italic;"&gt;//check the value in each row of column 2&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;var&lt;/span&gt; m &lt;span style="color: black;"&gt;=&lt;/span&gt; tbl&lt;span style="color: black;"&gt;.&lt;/span&gt;rows&lt;span style="color: black;"&gt;[&lt;/span&gt;j&lt;span style="color: black;"&gt;].&lt;/span&gt;cells&lt;span style="color: black;"&gt;[&lt;/span&gt;&lt;span style="color: black;"&gt;1&lt;/span&gt;&lt;span style="color: black;"&gt;].&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;innerHTML&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt;

&lt;span style="color: blue; font-weight: bold;"&gt;if&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;m&lt;span style="color: black;"&gt;!=&lt;/span&gt;rowHead &lt;span style="color: black;"&gt;||&lt;/span&gt; j&lt;span style="color: black;"&gt;==&lt;/span&gt;&lt;span style="color: black;"&gt;1&lt;/span&gt;&lt;span style="color: black;"&gt;){&lt;/span&gt;
rowHead&lt;span style="color: black;"&gt;=&lt;/span&gt;m&lt;span style="color: black;"&gt;;&lt;/span&gt;
tbl&lt;span style="color: black;"&gt;.&lt;/span&gt;rows&lt;span style="color: black;"&gt;[&lt;/span&gt;j&lt;span style="color: black;"&gt;].&lt;/span&gt;cells&lt;span style="color: black;"&gt;[&lt;/span&gt;&lt;span style="color: black;"&gt;0&lt;/span&gt;&lt;span style="color: black;"&gt;].&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;innerHTML&lt;/span&gt; &lt;span style="color: black;"&gt;=&lt;/span&gt; link&lt;span style="color: black;"&gt;;&lt;/span&gt;
tbl&lt;span style="color: black;"&gt;.&lt;/span&gt;rows&lt;span style="color: black;"&gt;[&lt;/span&gt;j&lt;span style="color: black;"&gt;].&lt;/span&gt;style&lt;span style="color: black;"&gt;.&lt;/span&gt;background &lt;span style="color: black;"&gt;=&lt;/span&gt; &lt;span style="color: black;"&gt;"#CCFF99"&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt;
&lt;span style="color: black;"&gt;}&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;else&lt;/span&gt;
tbl&lt;span style="color: black;"&gt;.&lt;/span&gt;rows&lt;span style="color: black;"&gt;[&lt;/span&gt;j&lt;span style="color: black;"&gt;].&lt;/span&gt;style&lt;span style="color: black;"&gt;.&lt;/span&gt;display &lt;span style="color: black;"&gt;=&lt;/span&gt; &lt;span style="color: black;"&gt;"none"&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt;
&lt;span style="color: black;"&gt;}&lt;/span&gt;
&lt;span style="color: black;"&gt;}&lt;/span&gt;

&lt;span style="color: blue; font-weight: bold;"&gt;window&lt;/span&gt;&lt;span style="color: black;"&gt;.&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;onload&lt;/span&gt;&lt;span style="color: black;"&gt;=&lt;/span&gt;collapseRows&lt;span style="color: black;"&gt;;&lt;/span&gt;

&lt;/pre&gt;Let me briefly explain what the script does. When a page has loaded, the &lt;span style="font-weight: bold;"&gt;collapseRows&lt;/span&gt; function is called. It looks for a table with a class named '&lt;span style="font-weight: bold;"&gt;expandable&lt;/span&gt;'. If such a table is found, a reference to the table is stored in a variable &lt;span style="font-weight: bold;"&gt;tbl&lt;/span&gt;, and the number of rows in the table is stored in a variable &lt;span style="font-weight: bold;"&gt;len&lt;/span&gt;.&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
var len = tbl.rows.length;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
Then, we create a variable that holds an html link that will call the &lt;span style="font-weight: bold;"&gt;toggleSection &lt;/span&gt;function when linked. The function parameter will contain a reference to the link itself. We using the &lt;span style="font-weight: bold;"&gt;this&lt;/span&gt; keyword here.&lt;br /&gt;
&lt;pre&gt;&lt;span style="color: blue; font-weight: bold;"&gt;var&lt;/span&gt; link &lt;span style="color: black;"&gt;=&lt;/span&gt; &lt;span style="color: black;"&gt;'&amp;lt;a href="#" onclick="toggleSection(this);return false;"&amp;gt;+ &amp;lt;/a&amp;gt; '&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;br /&gt;
The variable rowHead in the next statement will contain the text in the second column of the first row(not counting the table head). In this table it is January.&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
var rowHead = tbl.rows[1].cells[1].innerHTML;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
The next piece of the code loops through each row, and if the text in the second column contains repeating information, it hides that row. Also, it assigns a different color to the first row with non-duplicate text.&lt;br /&gt;
&lt;pre&gt;&lt;span style="color: blue; font-weight: bold;"&gt;for&lt;/span&gt; &lt;span style="color: black;"&gt;(&lt;/span&gt;j&lt;span style="color: black;"&gt;=&lt;/span&gt;&lt;span style="color: black;"&gt;1&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt; j &lt;span style="color: black;"&gt;&amp;lt;&lt;/span&gt; len&lt;span style="color: black;"&gt;;&lt;/span&gt;j&lt;span style="color: black;"&gt;++){&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;var&lt;/span&gt; m &lt;span style="color: black;"&gt;=&lt;/span&gt; tbl&lt;span style="color: black;"&gt;.&lt;/span&gt;rows&lt;span style="color: black;"&gt;[&lt;/span&gt;j&lt;span style="color: black;"&gt;].&lt;/span&gt;cells&lt;span style="color: black;"&gt;[&lt;/span&gt;&lt;span style="color: black;"&gt;1&lt;/span&gt;&lt;span style="color: black;"&gt;].&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;innerHTML&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;if&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;m&lt;span style="color: black;"&gt;!=&lt;/span&gt;rowHead &lt;span style="color: black;"&gt;||&lt;/span&gt; j&lt;span style="color: black;"&gt;==&lt;/span&gt;&lt;span style="color: black;"&gt;1&lt;/span&gt;&lt;span style="color: black;"&gt;){&lt;/span&gt;
rowHead&lt;span style="color: black;"&gt;=&lt;/span&gt;m&lt;span style="color: black;"&gt;;&lt;/span&gt;
tbl&lt;span style="color: black;"&gt;.&lt;/span&gt;rows&lt;span style="color: black;"&gt;[&lt;/span&gt;j&lt;span style="color: black;"&gt;].&lt;/span&gt;cells&lt;span style="color: black;"&gt;[&lt;/span&gt;&lt;span style="color: black;"&gt;0&lt;/span&gt;&lt;span style="color: black;"&gt;].&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;innerHTML&lt;/span&gt; &lt;span style="color: black;"&gt;=&lt;/span&gt; link&lt;span style="color: black;"&gt;;&lt;/span&gt;
tbl&lt;span style="color: black;"&gt;.&lt;/span&gt;rows&lt;span style="color: black;"&gt;[&lt;/span&gt;j&lt;span style="color: black;"&gt;].&lt;/span&gt;style&lt;span style="color: black;"&gt;.&lt;/span&gt;background &lt;span style="color: black;"&gt;=&lt;/span&gt; &lt;span style="color: black;"&gt;"#CCFF99"&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt;
&lt;span style="color: black;"&gt;}&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;else&lt;/span&gt;
tbl&lt;span style="color: black;"&gt;.&lt;/span&gt;rows&lt;span style="color: black;"&gt;[&lt;/span&gt;j&lt;span style="color: black;"&gt;].&lt;/span&gt;style&lt;span style="color: black;"&gt;.&lt;/span&gt;display &lt;span style="color: black;"&gt;=&lt;/span&gt; &lt;span style="color: black;"&gt;"none"&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt;
&lt;span style="color: black;"&gt;}&lt;/span&gt;

&lt;/pre&gt;The next function, &lt;span style="font-weight: bold;"&gt;toggleSection, &lt;/span&gt;hides or collapses rows with duplicate months. As a parameter, the function accepts a reference to the link that calls the function. Using the link reference, we get a reference to the containing table cell, row, and then the row index for the cell:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;var&lt;/span&gt; td &lt;span style="color: black;"&gt;=&lt;/span&gt; lnk&lt;span style="color: black;"&gt;.&lt;/span&gt;parentNode&lt;span style="color: black;"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;var&lt;/span&gt; tr &lt;span style="color: black;"&gt;=&lt;/span&gt; &lt;span style="color: black;"&gt;getParent&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;td&lt;span style="color: black;"&gt;,&lt;/span&gt; &lt;span style="color: black;"&gt;'tr'&lt;/span&gt;&lt;span style="color: black;"&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;var&lt;/span&gt; rowIndex &lt;span style="color: black;"&gt;=&lt;/span&gt; tr&lt;span style="color: black;"&gt;.&lt;/span&gt;rowIndex&lt;span style="color: black;"&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
We obtain text in the second column of that row (January or February, in this example):&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
var rowHead=table.rows[rowIndex].cells[1].innerHTML;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
Next, we switch the text of the link from plus to minus or vice versa.&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
lnk.innerHTML =(lnk.innerHTML == "+")?"-":"+";&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
Then, we prepare a style to be used for the next rows.&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
vStyle =(tbl.rows[rowIndex+1].style.display=='none')?'':'none';&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
Then, we loop through the table, and if the text in the second column of each row is the same as the text in the same column of the row that contains the link, we hide or show that row depending on its initial state.&lt;br /&gt;
&lt;pre&gt;&lt;span style="color: blue; font-weight: bold;"&gt;for&lt;/span&gt;&lt;span style="color: black;"&gt;(&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;var&lt;/span&gt; i &lt;span style="color: black;"&gt;=&lt;/span&gt; rowIndex&lt;span style="color: black;"&gt;+&lt;/span&gt;&lt;span style="color: black;"&gt;1&lt;/span&gt;&lt;span style="color: black;"&gt;;&lt;/span&gt; i &lt;span style="color: black;"&gt;&amp;lt;&lt;/span&gt; len&lt;span style="color: black;"&gt;;&lt;/span&gt;i&lt;span style="color: black;"&gt;++){&lt;/span&gt;
&lt;span style="color: blue; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: black;"&gt;(&lt;/span&gt;table&lt;span style="color: black;"&gt;.&lt;/span&gt;rows&lt;span style="color: black;"&gt;[&lt;/span&gt;i&lt;span style="color: black;"&gt;].&lt;/span&gt;cells&lt;span style="color: black;"&gt;[&lt;/span&gt;&lt;span style="color: black;"&gt;1&lt;/span&gt;&lt;span style="color: black;"&gt;].&lt;/span&gt;&lt;span style="color: blue; font-weight: bold;"&gt;innerHTML&lt;/span&gt;&lt;span style="color: black;"&gt;==&lt;/span&gt;rowHead&lt;span style="color: black;"&gt;){&lt;/span&gt;
table&lt;span style="color: black;"&gt;.&lt;/span&gt;rows&lt;span style="color: black;"&gt;[&lt;/span&gt;i&lt;span style="color: black;"&gt;].&lt;/span&gt;style&lt;span style="color: black;"&gt;.&lt;/span&gt;display&lt;span style="color: black;"&gt;=&lt;/span&gt; vStyle&lt;span style="color: black;"&gt;;&lt;/span&gt;
&lt;span style="color: black;"&gt;}&lt;/span&gt;

&lt;/pre&gt;We also hide the repeating text in the second column:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
table.rows[i].cells[1].style.visibility="hidden";&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
Don't forget, the table must contain an empty first column to hold a plus or minus sign and have an id named '&lt;span style="font-weight: bold;"&gt;expandable&lt;/span&gt;'.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2885018062563133508-1612136084042548487?l=js-code.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/vCVweop1HNT5TmwAGm5pG9onEDg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vCVweop1HNT5TmwAGm5pG9onEDg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/vCVweop1HNT5TmwAGm5pG9onEDg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/vCVweop1HNT5TmwAGm5pG9onEDg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavascriptTips/~4/egl1ooFYo9Q" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://js-code.blogspot.com/feeds/1612136084042548487/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://js-code.blogspot.com/2009/03/expandcollapse-rows-dynamically-with.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/1612136084042548487?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/1612136084042548487?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavascriptTips/~3/egl1ooFYo9Q/expandcollapse-rows-dynamically-with.html" title="Expand/Collapse Rows Dynamically with DOM and JavaScript" /><author><name>Eric</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/_z3bqutNd8ec/ScvpgdM_gmI/AAAAAAAAAWs/4b3SK5NLQ8s/s72-c/table1.JPG" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://js-code.blogspot.com/2009/03/expandcollapse-rows-dynamically-with.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkYFSHc7eip7ImA9WhRXEEk.&quot;"><id>tag:blogger.com,1999:blog-2885018062563133508.post-1901282948908939300</id><published>2009-03-26T13:30:00.000-07:00</published><updated>2011-12-16T06:01:59.902-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-12-16T06:01:59.902-08:00</app:edited><title>How to Change HTML Table Cell Value</title><content type="html">First, we need to get a reference to a table cell value.&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;var table = document.getElementById('myTableId');&lt;/code&gt;&lt;br /&gt;
An &lt;span style="font-style: italic;"&gt;HTMLTableElement &lt;/span&gt;has a &lt;span style="font-weight: bold;"&gt;rows &lt;/span&gt;property that refers to the table rows collection. An HTMLTableRowElement has a cells property that refers to the row cells collection.&lt;br /&gt;
&lt;br /&gt;
With this information at hand it is easy to get a reference to any cell.&lt;br /&gt;
&lt;br /&gt;
Let's say, we need to refer to the first column of the first row.&lt;br /&gt;
&lt;br /&gt;
Since the collection index starts at 0 we can get this reference using the following code:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;var cell = table.rows[0].cells[0];&lt;/code&gt;&lt;br /&gt;
The cell variable now refers to the cell in the first column and first row.&lt;br /&gt;
The data in the table cell is represented by a text node. We can get a reference to it by using the &lt;span style="font-weight: bold;"&gt;firstChild &lt;/span&gt;property of an HTMLElement.&lt;br /&gt;
&lt;br /&gt;
We obtain a reference to the text node value by using its &lt;span style="font-weight: bold;"&gt;data &lt;/span&gt;property.&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;var value = cell.firstChild.data;&lt;/code&gt;&lt;br /&gt;
Now it is easy to change the text in a table cell:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;cell.firstChild.data = 'my new text';&lt;br /&gt;&lt;br /&gt;&lt;/c&gt;&lt;/code&gt;&lt;br /&gt;
What if you have an &lt;b&gt;HTML object &lt;/b&gt;in your data cell, like a &lt;strong&gt;radio button &lt;/strong&gt;?&amp;nbsp;In this case, 'firstChild' property will refer to this object, and you can get all the properties of the object by referring to&amp;nbsp;the cell's firstChild property, e.g:&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;cell.firstChild.value &lt;br /&gt;cell.firstChild.name&lt;br /&gt;cell.firstChild.type&lt;br /&gt;&lt;/code&gt;&amp;nbsp;&lt;/code&gt; &lt;br /&gt;
&lt;h3&gt;
Change table cell value automatically&lt;/h3&gt;
&lt;br /&gt;To change a table cell value automatically we must assign an event handler to the cell &lt;span style="font-style: italic;"&gt;onblur &lt;/span&gt;event.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2885018062563133508-1901282948908939300?l=js-code.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/P0QV_l7aF-6chIbK6WdsVLZ7SNk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/P0QV_l7aF-6chIbK6WdsVLZ7SNk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/P0QV_l7aF-6chIbK6WdsVLZ7SNk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/P0QV_l7aF-6chIbK6WdsVLZ7SNk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/JavascriptTips/~4/eAHjFeDtOdU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://js-code.blogspot.com/feeds/1901282948908939300/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://js-code.blogspot.com/2009/03/how-to-change-html-table-cell-value.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/1901282948908939300?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/2885018062563133508/posts/default/1901282948908939300?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/JavascriptTips/~3/eAHjFeDtOdU/how-to-change-html-table-cell-value.html" title="How to Change HTML Table Cell Value" /><author><name>Eric</name><uri>http://www.blogger.com/profile/04738667434492418561</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>2</thr:total><feedburner:origLink>http://js-code.blogspot.com/2009/03/how-to-change-html-table-cell-value.html</feedburner:origLink></entry></feed>

