<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2885018062563133508</id><updated>2024-08-31T05:34:39.893-07:00</updated><category term="Table"/><category term="Functions"/><category term="DOM"/><category term="Array"/><category term="Books"/><category term="Cookies"/><category term="Form"/><category term="jQuery"/><title type='text'>JavaScript Tips</title><subtitle type='html'>This blog features pure JavaScript code. You don&#39;t need to use libraries to do stuff in JavaScript.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://js-code.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>21</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-2284208892471853657</id><published>2015-05-08T05:33:00.000-07:00</published><updated>2015-05-08T05:33:55.733-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><title type='text'>Toggle Enabled State on Submit Button from Checkbox with jQuery</title><content type='html'>&lt;pre style=&quot;background: #ffffff; color: black;&quot;&gt;&lt;html&gt;&lt;body style=&quot;background: #ffffff; color: black;&quot;&gt;&lt;pre&gt;
$&lt;span style=&quot;color: #808030;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #0000e6;&quot;&gt;#myCheckBox&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #808030;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #808030;&quot;&gt;.&lt;/span&gt;change&lt;span style=&quot;color: #808030;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #808030;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #808030;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: purple;&quot;&gt;{&lt;/span&gt;
        $&lt;span style=&quot;color: #808030;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #0000e6;&quot;&gt;input[type=&#39;submit&#39;]&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #808030;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #808030;&quot;&gt;.&lt;/span&gt;prop&lt;span style=&quot;color: #808030;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #0000e6;&quot;&gt;disabled&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #808030;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #808030;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: maroon; font-weight: bold;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #808030;&quot;&gt;.&lt;/span&gt;checked&lt;span style=&quot;color: #808030;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;;&lt;/span&gt;        
    &lt;span style=&quot;color: purple;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #808030;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;
&lt;/body&gt;&lt;/html&gt;&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://js-code.blogspot.com/feeds/2284208892471853657/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://js-code.blogspot.com/2015/05/toggle-enabled-state-on-submit-button.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/2284208892471853657'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/2284208892471853657'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2015/05/toggle-enabled-state-on-submit-button.html' title='Toggle Enabled State on Submit Button from Checkbox with jQuery'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-1901282948908939300</id><published>2014-03-21T13:30:00.000-07:00</published><updated>2014-04-29T11:31:29.448-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DOM"/><category scheme="http://www.blogger.com/atom/ns#" term="Table"/><title type='text'>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(&#39;myTableId&#39;);&lt;/code&gt;&lt;br /&gt;
An &lt;span style=&quot;font-style: italic;&quot;&gt;HTMLTableElement &lt;/span&gt;has a &lt;span style=&quot;font-weight: bold;&quot;&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&#39;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=&quot;font-weight: bold;&quot;&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=&quot;font-weight: bold;&quot;&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 = &#39;my new text&#39;;&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;b&gt;radio button &lt;/b&gt;?&amp;nbsp;In this case, &#39;firstChild&#39; property will refer to this object, and you can get all the properties of the object by referring to&amp;nbsp;the cell&#39;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;/code&gt;&amp;nbsp; &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=&quot;font-style: italic;&quot;&gt;onblur &lt;/span&gt;event.&lt;br /&gt;
&lt;br /&gt;
For DOM scripting, I would recommend an excellent book on the subject by Jeremy Keith &lt;a href=&quot;http://www.amazon.com/gp/product/1590595335/ref=as_li_ss_tl?ie=UTF8&amp;amp;tag=codingtips-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=1590595335&quot;&gt;DOM Scripting: Web Design with JavaScript and the Document Object Model&lt;/a&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://www.assoc-amazon.com/e/ir?t=codingtips-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=1590595335&quot; height=&quot;1&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0px;&quot; width=&quot;1&quot; /&gt;. It will teach you to work with DOM and JavaScript from the ground up.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;Some other posts you might find interesting:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://js-code.blogspot.ca/2011/05/highlight-table-rows.html&quot;&gt;How to Hightlight Table Rows&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://js-code.blogspot.ca/2012/05/extract-table-text.html&quot; target=&quot;_blank&quot;&gt;Extract Table Text&lt;/a&gt;&lt;br /&gt;
&lt;br /&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='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/1901282948908939300'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/1901282948908939300'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2009/03/how-to-change-html-table-cell-value.html' title='How to Change HTML Table Cell Value'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-3096712382649634139</id><published>2012-09-23T10:03:00.001-07:00</published><updated>2012-09-23T10:11:07.706-07:00</updated><title type='text'>Format Number with a Thousand Separator</title><content type='html'>Here are a couple of helpful functions to work with number.&lt;br /&gt;
The first one formats a number with a thousand separator. A comma is used as a thousands separator.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
function format(obj){
  var str = obj.toString();
  var re=/(-?\d+)(\d{3})/;
  while(re.test(str)){
   str=str.replace(re,&#39;$1,$2&#39;)
  }
  return str;
}
&lt;/pre&gt;
&lt;br /&gt;
This one removes formatting:&lt;br /&gt;
&lt;pre&gt;
function deformat(str){
 var re = /,/g;
   return str.replace(re,&#39;&#39;);
}
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://js-code.blogspot.com/feeds/3096712382649634139/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://js-code.blogspot.com/2012/09/format-number-with-thousand-separator.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/3096712382649634139'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/3096712382649634139'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2012/09/format-number-with-thousand-separator.html' title='Format Number with a Thousand Separator'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-8850846323648720448</id><published>2012-05-01T12:38:00.001-07:00</published><updated>2014-04-07T06:19:33.940-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DOM"/><category scheme="http://www.blogger.com/atom/ns#" term="Table"/><title type='text'>Extract Table Text</title><content type='html'>The following recursive function can be used to extract text from any HTML element including a table. &lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;var cnts= &#39;&#39;;
function getElementText(el){
 var cn=el.childNodes,i;
 if(el.nodeType==3){
     cnts += (el.nodeValue + &quot;\n&quot;);
 }
 for(i=0;i&amp;lt;cn.length;++i)
   getElementText(cn[i]);
}
&lt;/pre&gt;
&lt;br /&gt;
The function accepts an HTML object as a parameter. First it checks for the &lt;strong&gt;&lt;a href=&quot;http://www.javascriptkit.com/domref/nodetype.shtml&quot; target=&quot;_blank&quot;&gt;nodeType&lt;/a&gt;&lt;/strong&gt; property of the DOM element. If the &lt;strong&gt;nodeType&lt;/strong&gt; value is 3 (TEXT_NODE) the function grabs the element &lt;strong&gt;text&lt;/strong&gt; (nodeValue) and appends it to the global variable &lt;em&gt;cnts&lt;/em&gt;. As the final step the function calls itself supplying each element child as the parameter.&amp;nbsp; The only downside I see is using a global variable to hold the element contents. But so far I don&#39;t see any other way to achieve the same functionality.&lt;br /&gt;
&lt;br /&gt;
An interesting article about anonymous recursive functions can be found &lt;a href=&quot;http://jimbojw.com/wiki/index.php?title=Recursive_Anonymous_JavaScript_Functions&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. &lt;br /&gt;
&lt;br /&gt;
Another post you might find interesting:&amp;nbsp;&lt;a href=&quot;http://js-code.blogspot.ca/2012/03/hide-columns-in-table.html&quot; target=&quot;_blank&quot;&gt; Hide Columns in a Table&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://js-code.blogspot.com/feeds/8850846323648720448/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://js-code.blogspot.com/2012/05/extract-table-text.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/8850846323648720448'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/8850846323648720448'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2012/05/extract-table-text.html' title='Extract Table Text'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-2251282060199735444</id><published>2012-03-29T09:59:00.000-07:00</published><updated>2014-04-29T11:20:40.424-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Table"/><title type='text'>Edit Table Cell in Place</title><content type='html'>Let&#39;s create a function that will get a reference to a table cell as a parameter, and make the table cell editable. In other words, create Edit In Place. Our function will be very simple, and use only standard DOM methods. It will be called by clicking on the table cell. &lt;br /&gt;
&lt;pre&gt; function makeEditable(el){
 }
&lt;/pre&gt;
The &lt;b&gt;el&lt;/b&gt; variable will hold a reference to a table cell. Normally, a table cell will have one childNode - the text element. First we check whether this is the first click on the table cell: &lt;br /&gt;
&lt;pre&gt;  if(el.firstChild.nodeName !=&quot;INPUT&quot;){
  }
&lt;/pre&gt;
If it is so, we create an input element: &lt;br /&gt;
&lt;pre&gt; var input = document.createElement(&quot;INPUT&quot;);
&lt;/pre&gt;
Assign the value of the cell text to the input element and set different background: &lt;br /&gt;
&lt;pre&gt; input.value = el.firstChild.nodeValue;
   input.style.background = &quot;rgb(255,244,255)&quot;;
&lt;/pre&gt;
Turn autocomplete off to avoid the &#39;Permission denied to set property XULElement.selectedIndex&#39; error in Firefox. &lt;br /&gt;
&lt;pre&gt; input.setAttribute(&#39;autocomplete&#39;,&#39;off&#39;);
&lt;/pre&gt;
Replace the text with the input element we just created and set focus on it: &lt;br /&gt;
&lt;pre&gt;  el.replaceChild(input, el.firstChild);
  el.firstChild.select();
  el.firstChild.focus();
&lt;/pre&gt;
To turn the input element back into text, we&#39;ll do the reverse procedure - create a text node, and replace the input element with text: &lt;br /&gt;
&lt;pre&gt; var text= document.createTextNode(el.firstChild.value);
 el.replaceChild(text, el.firstChild);
&lt;/pre&gt;
The function will called from a cell element as follows: &lt;br /&gt;
&lt;pre&gt;onclick=makeEditable; &lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
Once a user turned the input back into text, you could apply various &lt;a href=&quot;http://en.wikipedia.org/wiki/Ajax_%28programming%29&quot;&gt;Ajax&lt;/a&gt; techniques to save the modified text on the server. &lt;br /&gt;
&lt;br /&gt;
Here is the full function listing: &lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;function&lt;/span&gt; makeEditable&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;
 &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;var&lt;/span&gt; el &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
 &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;el&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;firstChild&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;nodeName &lt;span style=&quot;color: #308080;&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;INPUT&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;
   &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;var&lt;/span&gt; &lt;span style=&quot;color: #007d45;&quot;&gt;input&lt;/span&gt; &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; document&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;createElement&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
    &lt;span style=&quot;color: #007d45;&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;value &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; el&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;firstChild&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;nodeValue&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
    &lt;span style=&quot;color: #007d45;&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;setAttribute&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;&#39;autocomplete&#39;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;&#39;off&#39;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
    &lt;span style=&quot;color: #007d45;&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;style&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;background &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;rgb(255,244,255)&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
    el&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;replaceChild&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #007d45;&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt; el&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;firstChild&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
    el&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;firstChild&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;select&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
    el&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;firstChild&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;focus&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
   &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;
   &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;
    &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;var&lt;/span&gt; text&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; document&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;createTextNode&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;el&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;firstChild&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;value&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
  el&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;replaceChild&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;text&lt;span style=&quot;color: #308080;&quot;&gt;,&lt;/span&gt; el&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;firstChild&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
   &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;
 &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;br /&gt;
When the &lt;i&gt;makeEditable&lt;/i&gt; function is called from a table cell, the keyword &lt;i&gt;this&lt;/i&gt; in the function refers to the table cell element. &lt;br /&gt;
&lt;h3&gt;
Unobtrusive JavaScript&lt;/h3&gt;
There is a way to attach a function to the onclick event in each table cell without having to write inline code. Here is how to do it: &lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #f6f8ff; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #000020;&quot;&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;function&lt;/span&gt; addEventHandlers&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;
  &lt;span style=&quot;color: #595979;&quot;&gt;//the table should have an id&lt;/span&gt;
  &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;var&lt;/span&gt; table &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; document&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;getElementById&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;&#39;example&#39;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
  &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;var&lt;/span&gt; tds &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; table&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;getElementsByTagName&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;&#39;td&#39;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
  &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;var&lt;/span&gt; i&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt; i&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;&amp;lt; &lt;/span&gt;&lt;span style=&quot;color: #000020;&quot;&gt;tds&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #000020;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: #000020;&quot;&gt; i&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #000020;&quot;&gt;
   &lt;/span&gt;&lt;span style=&quot;color: #595979;&quot;&gt;//no brackets after the function name&lt;/span&gt;&lt;span style=&quot;color: #000020;&quot;&gt;
   tds&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #000020;&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #000020;&quot;&gt;onclick &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #000020;&quot;&gt; makeEditable&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: #000020;&quot;&gt;
   tds&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #000020;&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #000020;&quot;&gt;title &lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #000020;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;&#39;Click to edit&#39;&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: #000020;&quot;&gt;
  &lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #000020;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
The last step is to make sure this function is called after a page has loaded: &lt;br /&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
window.onload = addEventHandlers;&lt;br /&gt;
&lt;div style=&quot;float: left; margin-right: 4px;&quot;&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
google_ad_client = &quot;ca-pub-8504512626105280&quot;;
/* 300x250, created 12/9/10 */
google_ad_slot = &quot;7115539031&quot;;
google_ad_width = 300;
google_ad_height = 250;
//&lt;/script&gt;
&lt;/div&gt;
--&amp;gt;&lt;script src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Related posts:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://js-code.blogspot.ca/2009/03/how-to-change-html-table-cell-value.html&quot; target=&quot;_blank&quot;&gt;How to Change HTML Table Cell Value&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://js-code.blogspot.ca/2012/03/hide-columns-in-table.html&quot; target=&quot;_blank&quot;&gt;Hide Columns in a Table&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://js-code.blogspot.com/feeds/2251282060199735444/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://js-code.blogspot.com/2012/03/edit-table-cell-in-place.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/2251282060199735444'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/2251282060199735444'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2012/03/edit-table-cell-in-place.html' title='Edit Table Cell in Place'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-9179779030082283527</id><published>2012-03-28T13:33:00.001-07:00</published><updated>2012-05-24T07:46:55.340-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Table"/><title type='text'>Delete Table Rows</title><content type='html'>To delete selected rows from a table, obviously, we need to add checkboxes to every table row. When a checkbox is checked, it means that that particular row will be deleted. Also, we need some method by which we could identify a selected row. The &lt;code&gt;value&lt;/code&gt; attribute of a checkbox is a very good candidate for that. It will equal a row index. As you know, row indices start at 0, so the value of first row checkbox will equal 0, the value of the second row checkbox will equal 1, and so on. &lt;br /&gt;
Now, we can write a function to be called from the Delete button: &lt;br /&gt;
First, we get a reference to the table: &lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;var table = document.getElementById(&quot;myTable&quot;);
&lt;/pre&gt;
&lt;br /&gt;
Then, we get a reference to the array of checkboxes in the table: &lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;var checks = table.getElementsByTagName(&quot;input&quot;);
&lt;/pre&gt;
&lt;br /&gt;
Normally, this array will contain all the inputs in the table, and we would have to use the &lt;code&gt;type&lt;/code&gt; property to get a reference to desired elements. However, if we are sure that there are no other inputs in the table other than the checkboxes, we can skip this check. &lt;br /&gt;
Now, we iterate through all the checkboxes. If the &lt;code&gt;checked&lt;/code&gt; property is true, we obtain the index of a row which is contained in the checkbox value property, and delete this row. Also, we have iterate backwards, because otherwise removing a row changes the subsequent row index by -1. Iterating backwards preserves our indices. &lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;for(var i= checks.length-1; i&amp;gt;=0; i --){
 if(checks[i].checked){
  var indx =  checks[i].value;
  table.deleteRow(indx);
 }
}
&lt;/pre&gt;
&lt;br /&gt;
The next step resets the values of the checkboxes to make sure that they correspond to the new row indices. &lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;var checks = table.getElementsByTagName(&quot;input&quot;);
for(var i= 0; i &amp;lt; checks.length; i++){
 checks[i].value=i;
}
&lt;/pre&gt;
&lt;br /&gt;
Here is the complete function listing : &lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f6f8ff; color: #000020;&quot;&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;function&lt;/span&gt; deleteRows&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;
 &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;var&lt;/span&gt; table &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; document&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;getElementById&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;myTable&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
 &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;var&lt;/span&gt; checks &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; table&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;getElementsByTagName&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;

 &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;var&lt;/span&gt; i&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; checks&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;length&lt;span style=&quot;color: #308080;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt; i&lt;span style=&quot;color: #308080;&quot;&gt;&amp;gt;=&lt;/span&gt;&lt;span style=&quot;color: #008c00;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt; i &lt;span style=&quot;color: #308080;&quot;&gt;--&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;
  &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;checks&lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;i&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;checked&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;
   &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;var&lt;/span&gt; indx &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;  checks&lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;i&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;value&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
   table&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;deleteRow&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;indx&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
  &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;
 &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;
 &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;var&lt;/span&gt; checks &lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; table&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;getElementsByTagName&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #1060b6;&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
 &lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #200080; font-weight: bold;&quot;&gt;var&lt;/span&gt; i&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #008c00;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt; i &lt;span style=&quot;color: #308080;&quot;&gt;&amp;lt;&lt;/span&gt; checks&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;length&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt; i&lt;span style=&quot;color: #308080;&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #406080;&quot;&gt;{&lt;/span&gt;
  checks&lt;span style=&quot;color: #308080;&quot;&gt;[&lt;/span&gt;i&lt;span style=&quot;color: #308080;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #308080;&quot;&gt;.&lt;/span&gt;value&lt;span style=&quot;color: #308080;&quot;&gt;=&lt;/span&gt;i&lt;span style=&quot;color: #406080;&quot;&gt;;&lt;/span&gt;
 &lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;
&lt;span style=&quot;color: #406080;&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;div style=&quot;float: left; margin-right: 4px;&quot;&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
google_ad_client = &quot;ca-pub-8504512626105280&quot;;
/* 300x250, created 12/9/10 */
google_ad_slot = &quot;7115539031&quot;;
google_ad_width = 300;
google_ad_height = 250;
//--&gt;
&lt;/script&gt;&lt;script src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://js-code.blogspot.com/feeds/9179779030082283527/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://js-code.blogspot.com/2012/03/delete-table-rows.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/9179779030082283527'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/9179779030082283527'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2012/03/delete-table-rows.html' title='Delete Table Rows'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-1327420712383751637</id><published>2012-03-26T10:32:00.002-07:00</published><updated>2012-03-28T05:40:05.044-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Table"/><title type='text'>Hide Columns in Table</title><content type='html'>To hide or show table columns, first we get a reference to the table
&lt;pre&gt;
var table = document.getElementsByTagName(&quot;table&quot;)[0];
&lt;/pre&gt;

Then we get a reference to the &lt;i&gt;rows &lt;/i&gt;collection:
&lt;pre&gt;
var rows = table.rows;
&lt;/pre&gt;

Let&#39;s say we want to hide the first column in the table. We iterate through each row and
set the &lt;i&gt;display&lt;/i&gt; property of the first element in the &lt;i&gt;cells&lt;/i&gt; collection to none.
&lt;pre&gt;
for(var i=0; i&lt; rows.length; i++){
 rows[i].cells[0].style.display=&#39;none&#39;;
}
&lt;/pre&gt;

To show a particular column, we would set the &lt;i&gt;display&lt;/i&gt; property to blank.
&lt;pre&gt;
for(var i=0; i&lt; rows.length; i++){
 rows[i].cells[0].style.display=&#39;&#39;;
}
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://js-code.blogspot.com/feeds/1327420712383751637/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://js-code.blogspot.com/2012/03/hide-columns-in-table.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/1327420712383751637'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/1327420712383751637'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2012/03/hide-columns-in-table.html' title='Hide Columns in Table'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-6465741383732768367</id><published>2012-03-26T10:26:00.004-07:00</published><updated>2012-03-28T13:16:20.034-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DOM"/><title type='text'>DOM Hyperlinks</title><content type='html'>First, here is the code. Then I&#39;ll explain it: &lt;br /&gt;
&lt;pre&gt; var link  = document.createElement(&quot;A&quot;);
 link.href = &quot;http://www.google.com&quot;;
 var atext = document.createTextNode(&quot;Google&quot;);
 link.appendChild(atext);
 oElement.appendChild(link);

&lt;/pre&gt;
First, you create an HTMLAnchorElement using a &lt;a href=&quot;http://www.w3schools.com/jsref/default.asp&quot;&gt;DOM &lt;/a&gt;method createElement(tagName). &lt;br /&gt;
&lt;pre&gt;var link  = document.createElement(&quot;A&quot;);&lt;/pre&gt;
Then, you set the &lt;i&gt;href &lt;/i&gt;property of the HTMLAnchorElement: &lt;br /&gt;
&lt;pre&gt;link.href = &quot;http://www.google.com&quot;;&lt;/pre&gt;
Next, you create a text node that will hold the clickable text: &lt;br /&gt;
&lt;pre&gt;var atext = document.createTextNode(&quot;Google&quot;);&lt;/pre&gt;
Then, append the text node to the HTMLAnchorElement: &lt;br /&gt;
&lt;pre&gt;link.appendChild(atext);&lt;/pre&gt;
Now, you can append the link element to another element on the page: &lt;br /&gt;
&lt;pre&gt;oElement.appendChild(link);&lt;/pre&gt;
oElement holds a reference to an HTML element on the page that will be a parent of the newly created hyperlink. &lt;br /&gt;
Here is the same code presented as a function that accepts 3 parameters: parent element, url and link text: &lt;br /&gt;
&lt;pre&gt;function createLink(parent, url, linkText){
 var link  = document.createElement(&quot;A&quot;);
 link.href = url;
 var atext = document.createTextNode(linkText);
 link.appendChild(atext);
 parent.appendChild(link);
}
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://js-code.blogspot.com/feeds/6465741383732768367/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://js-code.blogspot.com/2012/03/dom-hyperlinks.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/6465741383732768367'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/6465741383732768367'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2012/03/dom-hyperlinks.html' title='DOM Hyperlinks'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-8866300703835058270</id><published>2012-03-26T10:11:00.003-07:00</published><updated>2012-03-28T13:16:49.727-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Form"/><title type='text'>Check Radio Button State</title><content type='html'>If you have radio buttons and one of the buttons is checked by default, you may need to check if the buttons state has been changed, and only then proceed with form submission. Suppose you have a group of radio buttons named &#39;cities&#39;: &lt;br /&gt;
&lt;pre&gt;&amp;lt;input type=&quot;radio&quot; name=&quot;cities&quot; value=&quot;Paris&quot;&amp;gt; Paris&amp;lt;br&amp;gt;
&amp;lt;input type=&quot;radio&quot; name=&quot;cities&quot; value=&quot;London&quot; checked&amp;gt; London&amp;lt;br&amp;gt;
&amp;lt;input type=&quot;radio&quot; name=&quot;cities&quot; value=&quot;Berlin&quot;&amp;gt;Berlin&amp;lt;br&amp;gt;
&lt;/pre&gt;
Here is a JavaScript function that will return true if a radio button value has been changed, and false if not. We assumed that the form name is &lt;i&gt;frm1&lt;/i&gt;. &lt;br /&gt;
&lt;pre&gt;function checkRadioButtons(){
 var rr = document.frm1.cities;
 var len = rr.length;
 while(len--&amp;gt;0){
  if(rr[len].checked !=rr[len].defaultChecked)
   return true;
 }
 return false;
}
&lt;/pre&gt;
Radio buttons and checkboxes have a &lt;b&gt;defaultChecked&lt;/b&gt; property which reflects the initial state of an element&#39;s &lt;b&gt;checked&lt;/b&gt; attribute. The code loops through each radio button and checks whether the current &lt;b&gt;checked&lt;/b&gt; property is equal to the &lt;b&gt;defaultChecked&lt;/b&gt; property of an element, in which case it means that the element state has been changed. &lt;br /&gt;
This function is called on form submit as follows: &lt;b&gt;&#39;return checkRadioButtons()&#39;&lt;/b&gt;. If the function returns true, the form submission takes place. If the function returns false, nothing happens.</content><link rel='replies' type='application/atom+xml' href='http://js-code.blogspot.com/feeds/8866300703835058270/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://js-code.blogspot.com/2012/03/check-radio-button-state.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/8866300703835058270'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/8866300703835058270'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2012/03/check-radio-button-state.html' title='Check Radio Button State'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-100451324834477237</id><published>2012-03-26T09:53:00.002-07:00</published><updated>2012-03-28T17:53:11.330-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Functions"/><title type='text'>Highlight All Links on a Web Page</title><content type='html'>&lt;p&gt;
The following JavaScript code will highlight each html link on a web page when you hover your mouse over it.
&lt;p&gt;
Get an array of all html links on a web page:

&lt;pre&gt;
 var aa = document.getElementsByTagName(&#39;a&#39;);
&lt;/pre&gt;

&lt;p&gt;Loop through the array and assign anonymous functions on mouseover and mouseout events:

&lt;pre&gt;
    for(var i=0; i&amp;lt;aa.length; i++){
        aa[i].onmouseover = function () {this.style.backgroundColor=&#39;#cc0000&#39;}
        aa[i].onmouseout = function () {this.style.backgroundColor=&#39;#ffffff&#39;}
    }
&lt;/pre&gt;

&lt;p&gt;The above code works and is fine. However, there is a better and shorter solution that does not require JavaScript
and uses CSS. Here is how you do it. In your CSS file, include the following declaration :

&lt;pre&gt;
 a:hover {background-color:#cc0000;}
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://js-code.blogspot.com/feeds/100451324834477237/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://js-code.blogspot.com/2012/03/highlight-all-links-on-web-page.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/100451324834477237'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/100451324834477237'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2012/03/highlight-all-links-on-web-page.html' title='Highlight All Links on a Web Page'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-419150499205297744</id><published>2012-02-28T09:10:00.002-08:00</published><updated>2012-03-28T13:19:41.729-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Functions"/><title type='text'></title><content type='html'>&lt;h3&gt;
A JavaScript endsWith function &lt;/h3&gt;
The following JavaScript function checks whether a string ends with a specified string. &lt;br /&gt;
&lt;pre&gt;&lt;span class=&quot;reserved&quot;&gt;function&lt;/span&gt; endsWith(str, s){
 &lt;span class=&quot;reserved&quot;&gt;var&lt;/span&gt; reg = &lt;span class=&quot;reserved&quot;&gt;new&lt;/span&gt; RegExp (s + &quot;$&quot;);
 &lt;span class=&quot;reserved&quot;&gt;return&lt;/span&gt; reg.&lt;span class=&quot;reserved&quot;&gt;test&lt;/span&gt;(str);
}
&lt;/pre&gt;
The first argument is a string to be checked, the second one is a suffix to find. It returns &lt;i&gt;true&lt;/i&gt; if the string ends with a specified string, and returns &lt;i&gt;false&lt;/i&gt; if it does not. We use a &quot;$&quot; anchor to match the end of the string. The function is case-sensitive. Example: &lt;br /&gt;
&lt;pre&gt;&lt;span class=&quot;reserved&quot;&gt;var&lt;/span&gt; str=&quot;teens&quot;;
alert(endsWith(str, &quot;ns&quot;));
&lt;/pre&gt;
If you want to make the function into a method that could be used by all variables of a string type, you could use an object&#39;s &lt;a href=&quot;http://phrogz.net/JS/Classes/ExtendingJavaScriptObjectsAndClasses.html&quot;&gt;prototype&lt;/a&gt; property: &lt;br /&gt;
&lt;pre&gt;&lt;span class=&quot;reserved&quot;&gt;String.prototype&lt;/span&gt;.endsWith = function(s){
 &lt;span class=&quot;reserved&quot;&gt;var&lt;/span&gt; reg = &lt;span class=&quot;reserved&quot;&gt;new&lt;/span&gt; RegExp(s + &quot;$&quot;);
 &lt;span class=&quot;reserved&quot;&gt;return&lt;/span&gt; reg.test(this);
}
&lt;/pre&gt;
Then, you would use the function as follows: &lt;br /&gt;
&lt;pre&gt;alert(str.endsWith(&quot;ns&quot;));
&lt;/pre&gt;
&lt;h3&gt;
A JavaScript startsWith function &lt;/h3&gt;
The previous function used the &quot;$&quot; anchor to match the end of a string. To match the start of a string, JavaScript regular expressions use a &quot;^&quot; (caret) anchor. This information allows us to write a function that would match the beginning of a string: &lt;br /&gt;
&lt;pre&gt;&lt;span class=&quot;reserved&quot;&gt;function&lt;/span&gt; startsWith(str, s){
 &lt;span class=&quot;reserved&quot;&gt;var&lt;/span&gt; reg = &lt;span class=&quot;reserved&quot;&gt;new&lt;/span&gt; RegExp(&quot;^&quot; + s);
 &lt;span class=&quot;reserved&quot;&gt;return&lt;/span&gt; reg.&lt;span class=&quot;reserved&quot;&gt;test&lt;/span&gt;(str);
}
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://js-code.blogspot.com/feeds/419150499205297744/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://js-code.blogspot.com/2012/02/javascript-endswith-function-following.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/419150499205297744'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/419150499205297744'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2012/02/javascript-endswith-function-following.html' title=''/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-8239016757879135528</id><published>2012-02-24T10:56:00.001-08:00</published><updated>2012-03-28T13:20:02.854-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Cookies"/><title type='text'>A Script That Remembers Values Typed into a Text Box</title><content type='html'>&lt;style&gt;
.codeblock {
  display: block;
   margin: 1em;
   border: 1px solid #999;
   padding: 1em;
   background: #ffa;
  color: #000;
  font-family:  monaco, courier, &quot;courier new&quot;, monospace;
}
&lt;/style&gt;&lt;br /&gt;
HTTP cookies can be used both for server-side and client-side programming. There are many ways to use &lt;b&gt;cookies&lt;/b&gt; in Javascript. In this short tutorial we will concentrate on the client-side. The task is to build a script that will remember values users type in a text box and display them next time the users access the page. &lt;br /&gt;
Let&#39;s say we have a form with an input box &quot;project&quot; and a submit button. We want to capture the values entered by the user and save them for later use. Cookies seem to be an ideal solution to this problem. No server-side programming or maintenance. &lt;br /&gt;
A working example is located &lt;a href=&quot;http://www.blogger.com/test/cookies_example.html&quot;&gt;here &lt;/a&gt;.&lt;br /&gt;
We&#39;ll need two functions to read and set cookies. They are pretty much standard and can be easily found on the web. &lt;br /&gt;
Let&#39;s start with a function that sets the &lt;b&gt;cookie.&lt;/b&gt; &lt;br /&gt;
&lt;pre class=&quot;codeblock&quot;&gt;function setCookie (name, value, expires,
  path, domain, secure) {
     document.cookie =
      name + &quot;=&quot;
      + escape(value)
      + ((expires) ? &quot;; expires=&quot;
      + expires.toGMTString() : &quot;&quot;)
      + ((path) ? &quot;; path=&quot; + path : &quot;&quot;)
      + ((domain) ? &quot;; domain=&quot; + domain : &quot;&quot;)
      + ((secure) ? &quot;; secure&quot; : &quot;&quot;);
}
&lt;/pre&gt;
The parameters to the function are self-explanatory: &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;dd&gt;&lt;var&gt;name&lt;/var&gt; is the cookie name we are going to use&lt;/dd&gt;&lt;dd&gt;&lt;var&gt;value&lt;/var&gt; is the cookie&#39;s value&lt;/dd&gt;&lt;dd&gt;&lt;var&gt;expires&lt;/var&gt; - a date that the cookie will expire.&lt;/dd&gt;&lt;br /&gt;
The &lt;var&gt;path&lt;/var&gt; sets the top level directory from which a cookie can be read. &lt;br /&gt;
Set the path of a cookie to the top-level directory of your Web pages, and the cookie is readable by all your Web pages.&lt;/dd&gt; &lt;br /&gt;
To get a cookie value we&#39;ll use the following function:&lt;br /&gt;
&lt;pre class=&quot;codeblock&quot;&gt; function getCookie(name) {
  &lt;span class=&quot;green&quot;&gt;// break cookie into array of bites&lt;/span&gt;
   var bites = document.cookie.split(&quot;; &quot;);
    for (var i=0; i &amp;lt; bites.length; i++) {
     &lt;span class=&quot;green&quot;&gt;// break into name and value &lt;/span&gt;
      nextbite = bites[i].split(&quot;=&quot;);
      &lt;span class=&quot;green&quot;&gt;// if name matches &lt;/span&gt;
      if (nextbite[0] == name)
      &lt;span class=&quot;green&quot;&gt;// return value &lt;/span&gt;
       return unescape(nextbite[1]);
    }
    return null;
 }
 &lt;/pre&gt;
Let&#39;s write a function that would add values to the existing &lt;b&gt;cookie&lt;/b&gt;. 2 arguments will be passed to the function: &lt;var&gt;cookieName&lt;/var&gt; and &lt;var&gt;formField&lt;/var&gt;. &lt;br /&gt;
First, let&#39;s get the value typed by the user: &lt;code&gt;&lt;/code&gt;&lt;br /&gt;
Now, we&#39;ll set the expiry date to 30 days from today.: &lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
Get the contents of the cookie using the getCookie function: &lt;br /&gt;
&lt;code&gt;var contents= getCookie(cookieName);&lt;/code&gt; &lt;br /&gt;
Add the new value typed by the user to the existing cookie contents. &lt;code&gt;&lt;/code&gt;&lt;br /&gt;
We chose to separate values by a period. You can use any other separators.&lt;br /&gt;
The last thing to do is to send the new cookie contents to our setCookie function: &lt;code&gt;&lt;/code&gt;&lt;br /&gt;
Here is the full listing of the function: &lt;br /&gt;
&lt;pre class=&quot;codeblock&quot;&gt;function addString(cookieName, formField){
 var field = eval (&quot;document.forms[0].&quot;+ formField);
 var txtVal =field.value;
 var expires = new Date();
 expires.setDate(expires.getDate() + 30);
 var contents= getCookie(cookieName);
 if(contents != null &amp;amp;&amp;amp; contents.indexOf(txtVal)&amp;lt;0)
  contents+=&quot;.&quot;+txtVal;
 else if(contents == null)
  contents = txtVal;

 setCookie(cookieName, contents, expires,&quot;/&quot;);
}
&lt;/pre&gt;
&lt;br /&gt;
We&#39;ll call this function from the onSubmit event of the form, like this:&lt;br /&gt;
&amp;lt;form onSubmit=&#39;addString (&quot;example&quot;,&quot;txt1&quot;)&#39;&amp;gt; &lt;br /&gt;
Now, the only thing to do is to write the contents of the cookie on the HTML page. &lt;br /&gt;
Here is the function that does it: &lt;br /&gt;
&lt;pre class=&quot;codeblock&quot;&gt;function writeCookieValues (val) {
 if(val!= null &amp;amp;&amp;amp; val.length&amp;gt;0){
  var str = new String(val);
&lt;span class=&quot;green&quot;&gt; //split the resulting array by a separator&lt;/span&gt;
&lt;span class=&quot;green&quot;&gt; //used earlier in the addString function&lt;/span&gt;
 var aPr = str.split(&quot;.&quot;);
 for(var i=0; i &amp;lt; aPr.length; i++)
  document.write(aPr [i]+&quot;&amp;lt;br&amp;gt;&quot;);
 }
}
&lt;/pre&gt;
Use it like this:&lt;br /&gt;
&amp;lt;script language=&#39;JavaScript&#39;&amp;gt; writeCookieValues (getCookie(&quot;example&quot;)); &amp;lt;/script&amp;gt; &lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://js-code.blogspot.com/feeds/8239016757879135528/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://js-code.blogspot.com/2012/02/script-that-remembers-values-typed-into.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/8239016757879135528'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/8239016757879135528'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2012/02/script-that-remembers-values-typed-into.html' title='A Script That Remembers Values Typed into a Text Box'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-8683468196245470845</id><published>2012-02-24T10:47:00.002-08:00</published><updated>2012-03-28T13:20:18.650-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Functions"/><title type='text'>A JavaScript Function that Allows Only Numbers</title><content type='html'>&lt;style&gt;
.codeblock {
  display: block;
   margin: 1em;
   border: 1px solid #999;
   padding: 1em;
   background: #ffa;
  color: #000;
  font-family:  monaco, courier, &quot;courier new&quot;, monospace;
}
&lt;/style&gt;This little function will force users to type numbers, commas and periods only. &lt;br /&gt;
&lt;pre class=&quot;codeblock&quot;&gt; function noAlpha(obj){
 reg = /[^0-9.,]/g;
 obj.value =  obj.value.replace(reg,&quot;&quot;);
 }

&lt;/pre&gt;
&lt;i&gt;reg = /[^0-9.,]/g&lt;/i&gt; is a &lt;a href=&quot;http://en.wikipedia.org/wiki/Regular_expression&quot;&gt;regular expression&lt;/a&gt; that basically says: look for any numbers from 0 to 9, periods and commas globally. &lt;br /&gt;
Usage:&lt;br /&gt;
&lt;code&gt;&amp;lt;input type=text onKeyUp=&#39;noAlpha(this)&#39; onKeyPress=&#39;noAlpha(this)&#39;&amp;gt;&lt;/code&gt; &lt;br /&gt;
&lt;br /&gt;
Try it &lt;a href=&quot;http://js-code.blogspot.com/p/numbers-only.html&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is a version of this function that does not use regular expressions and allows numbers only. &lt;br /&gt;
&lt;pre class=&quot;codeblock&quot;&gt;function forceNumbers(obj) {
 if ( obj.value.length == 0)
  return;

 if (!parseInt(obj.value,10) &amp;amp;&amp;amp; obj.value != 0)   {
  alert(&quot;Please enter a valid Number&quot;);
  obj.value = &#39;&#39;;
  obj.focus();
  obj.select();
 }
 else {
  obj.value = &#39;&#39; + parseInt(obj.value,10);
 }
}
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://js-code.blogspot.com/feeds/8683468196245470845/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://js-code.blogspot.com/2012/02/blog-post.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/8683468196245470845'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/8683468196245470845'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2012/02/blog-post.html' title='A JavaScript Function that Allows Only Numbers'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-4385296018872282786</id><published>2011-06-23T13:44:00.000-07:00</published><updated>2012-03-28T13:20:29.738-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Books"/><title type='text'>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=&quot;http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;amp;location=http%3A%2F%2Fwww.amazon.com%2FAjax-Action-Dave-Crane%2Fdp%2F1932394613%2Fsr%3D1-1%2Fqid%3D1167844379%3Fie%3DUTF8%26s%3Dbooks&amp;amp;tag=codingtips-20&amp;amp;linkCode=ur2&amp;amp;camp=1789&amp;amp;creative=9325&quot;&gt;Ajax in Action &lt;/a&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://www.assoc-amazon.com/e/ir?t=codingtips-20&amp;amp;l=ur2&amp;amp;o=1&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0px;&quot; width=&quot;1&quot; /&gt;&lt;br /&gt;by Dave Crane, Eric Pascarello, Darren James&lt;br /&gt;&lt;div class=&quot;rcom&quot;&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&#39;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&#39;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;/li&gt;
&lt;li&gt;&lt;br /&gt;&lt;a href=&quot;http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;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;amp;tag=codingtips-20&amp;amp;linkCode=ur2&amp;amp;camp=1789&amp;amp;creative=9325&quot;&gt;Professional Ajax (Programmer to Programmer) (Paperback)&lt;/a&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://www.assoc-amazon.com/e/ir?t=codingtips-20&amp;amp;l=ur2&amp;amp;o=1&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0px;&quot; width=&quot;1&quot; /&gt;&lt;br /&gt;&lt;br /&gt;by Nicholas C. Zakas, Jeremy McPeak, Joe Fawcett&lt;br /&gt;&lt;div class=&quot;rcom&quot;&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&#39;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;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;&lt;a href=&quot;http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;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;amp;tag=codingtips-20&amp;amp;linkCode=ur2&amp;amp;camp=1789&amp;amp;creative=9325&quot;&gt;AJAX and PHP: Building Responsive Web Applications (Paperback)&lt;/a&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://www.assoc-amazon.com/e/ir?t=codingtips-20&amp;amp;l=ur2&amp;amp;o=1&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0px;&quot; width=&quot;1&quot; /&gt;&lt;br /&gt;by Cristian Darie, Bogdan Brinzarea, Filip Chereches-Tosa, Mihai Bucica&lt;br /&gt;&lt;div class=&quot;rcom&quot;&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;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;&lt;a href=&quot;http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;amp;location=http%3A%2F%2Fwww.amazon.com%2FAjax-Dummies-Computer-Tech%2Fdp%2F0471785970%2Fsr%3D1-14%2Fqid%3D1167844859%3Fie%3DUTF8%26s%3Dbooks&amp;amp;tag=codingtips-20&amp;amp;linkCode=ur2&amp;amp;camp=1789&amp;amp;creative=9325&quot;&gt;Ajax For Dummies (For Dummies (Computer/Tech)) (Paperback)&lt;/a&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; height=&quot;1&quot; src=&quot;http://www.assoc-amazon.com/e/ir?t=codingtips-20&amp;amp;l=ur2&amp;amp;o=1&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; margin: 0px;&quot; width=&quot;1&quot; /&gt;&lt;br /&gt;by Steve Ph.D. Holzner&lt;br /&gt;&lt;div class=&quot;rcom&quot;&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 &quot;just another Dummies book&quot;, I don&#39;t know that I&#39;d be so hasty...&lt;br /&gt;
&lt;pre&gt;Contents:
Part 1 - Getting Started: Ajax 101; It&#39;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;/li&gt;
&lt;/ul&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'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/4385296018872282786'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2011/06/top-rated-ajax-books.html' title='Top Rated Ajax Books'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-2004252283009427070</id><published>2011-05-02T13:19:00.000-07:00</published><updated>2014-04-29T11:30:03.376-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Table"/><title type='text'>Highlight HTML Table Rows with JavaScript</title><content type='html'>&lt;h3 style=&quot;margin-top: 50px;&quot;&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(&#39;myTable2&#39;);
 for (var i=0;i &amp;lt; table.rows.length;i++)
 {
  table.rows[i].onmouseover = function () {
   this.origColor=this.style.backgroundColor;
   this.style.backgroundColor=&#39;#BCD4EC&#39;;
  }
  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;div style=&quot;margin-right: 4px;&quot;&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
google_ad_client = &quot;ca-pub-8504512626105280&quot;;
/* 300x250, created 12/9/10 */
google_ad_slot = &quot;7115539031&quot;;
google_ad_width = 300;
google_ad_height = 250;
//&lt;/script&gt;
&lt;/div&gt;
--&amp;gt;
&lt;script src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;
&lt;h3 style=&quot;margin-top: 50px;&quot;&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(&#39;myTable3&#39;);
 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=&#39;#BCD4EC&#39;;
    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;br /&gt;
&lt;br /&gt;
Related posts:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://js-code.blogspot.ca/2012/03/hide-columns-in-table.html&quot; target=&quot;_blank&quot;&gt;Hide columns in a table&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://js-code.blogspot.ca/2009/03/expandcollapse-rows-dynamically-with.html&quot; target=&quot;_blank&quot;&gt;Expand/collapse rows dynamically&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&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'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/2004252283009427070'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2011/05/highlight-table-rows.html' title='Highlight HTML Table Rows with JavaScript'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-7937434368323064632</id><published>2011-05-02T13:11:00.000-07:00</published><updated>2012-03-28T13:21:02.790-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Table"/><title type='text'>A Simple Way to Highlight Table Cells with JavaScript</title><content type='html'>&lt;h3 style=&quot;margin-top: 50px;&quot;&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(&#39;myTable2&#39;);
 for (var i=0;i &amp;lt; table.rows.length;i++)
 {
  table.rows[i].onmouseover = function () {
   this.origColor=this.style.backgroundColor;
   this.style.backgroundColor=&#39;#BCD4EC&#39;;
  }
  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=&quot;margin-top: 50px;&quot;&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(&#39;myTable3&#39;);
 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=&#39;#BCD4EC&#39;;
    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.</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'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/7937434368323064632'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2011/05/simple-way-to-highlight-table-cells.html' title='A Simple Way to Highlight Table Cells with JavaScript'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-8026086644346932303</id><published>2010-12-10T06:47:00.000-08:00</published><updated>2012-03-28T13:21:19.980-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Functions"/><title type='text'>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 = /&quot;/g;
 var newstr = &#39;\\&quot;&#39;;
 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;br /&gt;
&lt;pre&gt;reg = /&quot;/g;
 &lt;/pre&gt;
The second line defines our replacement string - &lt;b&gt;\&quot; &lt;/b&gt;&lt;br /&gt;
The backslash in front of the quote has to be escaped with another backslash. &lt;br /&gt;
&lt;pre&gt;newstr = &#39;\\&quot;&#39;;&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;br /&gt;
&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;br /&gt;
&lt;pre&gt;function insertBackslashBeforeSingleQuote(str){
 var reg = /&#39;/g;
 var newstr = &quot;\\&#39;&quot;
 return str.replace(reg,newstr);
}&lt;/pre&gt;
&lt;div style=&quot;float: left; margin-right: 4px;&quot;&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
google_ad_client = &quot;ca-pub-8504512626105280&quot;;
/* 300x250, created 12/9/10 */
google_ad_slot = &quot;7115539031&quot;;
google_ad_width = 300;
google_ad_height = 250;
//--&gt;
&lt;/script&gt;&lt;script src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Some other posts:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://js-code.blogspot.ca/2012/02/javascript-endswith-function-following.html&quot;&gt;A JavaScript endsWith function&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://js-code.blogspot.ca/2011/05/highlight-table-rows.html&quot;&gt;Highlight HTML Table Rows with JavaScript&lt;/a&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'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/8026086644346932303'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2010/12/insert-backslash-before-double-quote.html' title='Insert Backslash Before a Double Quote'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-3742144016502440050</id><published>2010-11-17T06:04:00.000-08:00</published><updated>2012-04-04T11:55:32.975-07:00</updated><title type='text'>&quot;Event is Not Defined&quot; 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=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Consolas; font-size: 11pt; padding: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; inputs = document.getElementsByTagName(&lt;span style=&quot;color: #a31515;&quot;&gt;&#39;input&#39;&lt;/span&gt;);&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;for&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; i = 0; i &amp;lt; inputs.length; i++) {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (inputs[i].type == &lt;span style=&quot;color: #a31515;&quot;&gt;&#39;text&#39;&lt;/span&gt;) {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; inputs[i].onkeypress = &lt;span style=&quot;color: blue;&quot;&gt;function&lt;/span&gt;() { &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; isNumericKey(event); }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&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=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Consolas; font-size: 11pt; padding: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: green;&quot;&gt;/* Numeric Validation */&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;function&lt;/span&gt; isNumericKey(evt) {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; charCode = (evt.which) ? evt.which : event.keyCode;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&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=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt; {&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
} &lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp; &lt;/div&gt;
&lt;/div&gt;
This code will work perfectly in IE and it won&#39;t allow users to type any other characters than numeric. However, in Firefox, it will throw an error: &quot;event is not defined&quot;.&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=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Consolas; font-size: 11pt; padding: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt; (event) == &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;undefined&quot;&lt;/span&gt;)&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; inputs[i].onkeypress = isNegativeNumericKey;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; inputs[i].onkeypress = &lt;span style=&quot;color: blue;&quot;&gt;function&lt;/span&gt;() { &lt;span style=&quot;color: blue;&quot;&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=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt; (window.event) == &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;undefined&quot;&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=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Consolas; font-size: 11pt; padding: 8px;&quot;&gt;
&lt;br /&gt;
inputs[i].onkeypress = &lt;span style=&quot;color: blue;&quot;&gt;function&lt;/span&gt;(event) { &lt;span style=&quot;color: blue;&quot;&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=&quot;http://stackoverflow.com/questions/3774468/event-is-undefined-in-ie-works-in-firefox&quot;&gt;normalize the Event interface&lt;/a&gt; in the function body:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background: none repeat scroll 0% 0% white; color: black; font-family: Consolas; font-size: 11pt; padding: 8px;&quot;&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;function&lt;/span&gt;(event) {&amp;nbsp; &lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&amp;nbsp;&amp;nbsp; &lt;b&gt;event = event || window.event;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp;&amp;nbsp; return&lt;/span&gt; isNumericKey(event);&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;margin: 0px;&quot;&gt;
}&lt;/div&gt;
&lt;/div&gt;

&lt;div style=&quot;float: none; margin-right: 4px;&quot;&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
google_ad_client = &quot;ca-pub-8504512626105280&quot;;
/* 300x250, created 12/9/10 */
google_ad_slot = &quot;7115539031&quot;;
google_ad_width = 300;
google_ad_height = 250;
//--&gt;
&lt;/script&gt;
&lt;script src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;
&lt;/div&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='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/3742144016502440050'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/3742144016502440050'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2010/11/event-is-not-defined-error-in-firefox.html' title='&quot;Event is Not Defined&quot; Error in Firefox'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-5761048214960950078</id><published>2009-12-09T13:00:00.000-08:00</published><updated>2012-03-28T13:21:50.402-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Table"/><title type='text'>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=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8MMmP1HtlLOHE4x9xArkLAhhqZnvDTPX9eZRFvj8SdhBOlJRo9yoGA1MO2SUOwzxDLMroSnpbAhDG80naMs4VrXyX1syi85PMw419lHtdgX9tui6WPL08sRcVFTeEbb098RqnoKjw7kI/s1600/graph.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;89&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8MMmP1HtlLOHE4x9xArkLAhhqZnvDTPX9eZRFvj8SdhBOlJRo9yoGA1MO2SUOwzxDLMroSnpbAhDG80naMs4VrXyX1syi85PMw419lHtdgX9tui6WPL08sRcVFTeEbb098RqnoKjw7kI/s320/graph.jpg&quot; width=&quot;238&quot; /&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;/code&gt;&lt;br /&gt;
It assumes you set a style for a &quot;graph&quot; 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 &quot;graph&quot; class:&lt;br /&gt;
&lt;span style=&quot;font-style: italic;&quot;&gt;-moz-border-radius: 10px;&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;var tbl = document.getElementById(&#39;tbl&#39;);
for(var i=0; i&amp;lt;tbl.rows.length; i++){
var val = tbl.rows[i].cells[0].innerHTML;
var span = document.createElement(&quot;span&quot;);
span.style.width = val/100*100;
span.className = &quot;graph&quot;;
var cell =tbl.rows[i].cells[1];
cell.style.textAlign= &#39;left&#39;;
cell.appendChild(span);
}
&lt;/pre&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'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/5761048214960950078'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2009/12/here-is-simple-script-to-add-graph-to.html' title='A Graph in Table Without Image'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8MMmP1HtlLOHE4x9xArkLAhhqZnvDTPX9eZRFvj8SdhBOlJRo9yoGA1MO2SUOwzxDLMroSnpbAhDG80naMs4VrXyX1syi85PMw419lHtdgX9tui6WPL08sRcVFTeEbb098RqnoKjw7kI/s72-c/graph.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-3224387101668235009</id><published>2009-05-20T06:08:00.000-07:00</published><updated>2012-03-29T16:57:19.691-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Array"/><title type='text'>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 = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;];&lt;br /&gt;
&lt;br /&gt;
for (var prop in arr)&lt;br /&gt;
alert (prop + &quot;:&quot;+ 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 style=&quot;margin-right: 4px;&quot;&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
google_ad_client = &quot;ca-pub-8504512626105280&quot;;
/* 300x250, created 12/9/10 */
google_ad_slot = &quot;7115539031&quot;;
google_ad_width = 300;
google_ad_height = 250;
//--&gt;
&lt;/script&gt;
&lt;script src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;
&lt;/div&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'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/3224387101668235009'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2009/05/enumerate-through-array-object.html' title='Enumerate Array or Object'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2885018062563133508.post-1612136084042548487</id><published>2009-03-26T13:38:00.000-07:00</published><updated>2012-05-24T07:40:16.378-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Table"/><title type='text'>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=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5jqsuvFXluNfkKboo2YBXgoT7y0FeTRYM5VhisbGNzrlKSAOu9DeVXbDc4wlX7PR_avzEYvLF933F7PQsoYGPZ6TQegGxOfW4uiGMT2F36j9thJCCQf1vEF7QywYxQ00G2PCS-IW3cK0/s1600-h/table1.JPG&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; id=&quot;BLOGGER_PHOTO_ID_5317600528845210210&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5jqsuvFXluNfkKboo2YBXgoT7y0FeTRYM5VhisbGNzrlKSAOu9DeVXbDc4wlX7PR_avzEYvLF933F7PQsoYGPZ6TQegGxOfW4uiGMT2F36j9thJCCQf1vEF7QywYxQ00G2PCS-IW3cK0/s320/table1.JPG&quot; style=&quot;cursor: pointer; float: none; height: 196px; margin: 0pt 0pt 10px 10px; width: 256px;&quot; /&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=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOV447ir9ZVWHhhw6I82IPvpB8i9TZc2CSnjkh2GXjo3A6muqPz-uKND6qJgnXPHMp7J0Aeb0-iJEHYcnQyNFJSNyt0YBbhXcDHob-m1PbcMTtWgZQNqn0JGkujb8s095RMBDXYt2V5PU/s1600-h/table2.JPG&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; id=&quot;BLOGGER_PHOTO_ID_5317600802671322658&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOV447ir9ZVWHhhw6I82IPvpB8i9TZc2CSnjkh2GXjo3A6muqPz-uKND6qJgnXPHMp7J0Aeb0-iJEHYcnQyNFJSNyt0YBbhXcDHob-m1PbcMTtWgZQNqn0JGkujb8s095RMBDXYt2V5PU/s320/table2.JPG&quot; style=&quot;cursor: pointer; float: left; height: 139px; margin: 0pt 10px 10px 0pt; width: 320px;&quot; /&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=&quot;color: blue; font-weight: bold;&quot;&gt;var&lt;/span&gt; tbl&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;

&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;getParent&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;el&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt; pTagName&lt;span style=&quot;color: black;&quot;&gt;) {&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;el &lt;span style=&quot;color: black;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;return null&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;else if&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;el&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;nodeType &lt;span style=&quot;color: black;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; el&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;tagName&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;toLowerCase&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;() ==&lt;/span&gt; pTagName&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;toLowerCase&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;())&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;return&lt;/span&gt; el&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;else&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;getParent&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;el&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;parentNode&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt; pTagName&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;


&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;toggleSection&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;lnk&lt;span style=&quot;color: black;&quot;&gt;){&lt;/span&gt;

&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;var&lt;/span&gt; td &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; lnk&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;parentNode&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;var&lt;/span&gt; table &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;getParent&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;td&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&#39;TABLE&#39;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;var&lt;/span&gt; len &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; table&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rows&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;var&lt;/span&gt; tr &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;getParent&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;td&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;&#39;tr&#39;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;var&lt;/span&gt; rowIndex &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; tr&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rowIndex&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;var&lt;/span&gt; rowHead&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;table&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rows&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;rowIndex&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;cells&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;innerHTML&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;

lnk&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;innerHTML&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;=(&lt;/span&gt;lnk&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;innerHTML&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;&quot;+&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;?&lt;span style=&quot;color: black;&quot;&gt;&quot;-&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&quot;+&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
vStyle &lt;span style=&quot;color: black;&quot;&gt;=(&lt;/span&gt;tbl&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rows&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;rowIndex&lt;span style=&quot;color: black;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;style&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;display&lt;span style=&quot;color: black;&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&#39;none&#39;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;?&lt;span style=&quot;color: black;&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&#39;none&#39;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;

&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;var&lt;/span&gt; i &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; rowIndex&lt;span style=&quot;color: black;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt; i &lt;span style=&quot;color: black;&quot;&gt;&amp;lt;&lt;/span&gt; len&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;i&lt;span style=&quot;color: black;&quot;&gt;++){&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;table&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rows&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;i&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;cells&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;innerHTML&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;==&lt;/span&gt;rowHead&lt;span style=&quot;color: black;&quot;&gt;){&lt;/span&gt;
table&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rows&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;i&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;style&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;display&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; vStyle&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
table&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rows&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;i&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;cells&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;style&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;visibility&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&quot;hidden&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;

&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;collapseRows&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(){&lt;/span&gt;
tables &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;document&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;getElementsByTagName&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&quot;table&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;i &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt; i &lt;span style=&quot;color: black;&quot;&gt;&amp;lt;&lt;/span&gt; tables&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;i&lt;span style=&quot;color: black;&quot;&gt;++){&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;tables&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;i&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;className&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;indexOf&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&quot;expandable&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;) != -&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;
 tbl &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;tables&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;i&lt;span style=&quot;color: black;&quot;&gt;];&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;

&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;typeof&lt;/span&gt; tbl&lt;span style=&quot;color: black;&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&#39;undefined&#39;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;){&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt; alert&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&quot;Could not find a table of expandable class&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt; return&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;

&lt;span style=&quot;color: green; font-style: italic;&quot;&gt;//assume the first row is headings and the first column is empty&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;var&lt;/span&gt; len &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; tbl&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rows&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;var&lt;/span&gt; link &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;&#39;&amp;lt;a href=&quot;#&quot; onclick=&quot;toggleSection(this);return false;&quot;&amp;gt;+ &amp;lt;/a&amp;gt; &#39;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;

&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;var&lt;/span&gt; rowHead &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; tbl&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rows&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;cells&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;innerHTML&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;

&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;j&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt; j &lt;span style=&quot;color: black;&quot;&gt;&amp;lt;&lt;/span&gt; len&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;j&lt;span style=&quot;color: black;&quot;&gt;++){&lt;/span&gt;
&lt;span style=&quot;color: green; font-style: italic;&quot;&gt; //check the value in each row of column 2&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt; var&lt;/span&gt; m &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; tbl&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rows&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;j&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;cells&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;innerHTML&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;

&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt; if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;m&lt;span style=&quot;color: black;&quot;&gt;!=&lt;/span&gt;rowHead &lt;span style=&quot;color: black;&quot;&gt;||&lt;/span&gt; j&lt;span style=&quot;color: black;&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;){&lt;/span&gt;
  rowHead&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;m&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
  tbl&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rows&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;j&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;cells&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;innerHTML&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; link&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
  tbl&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rows&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;j&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;style&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;background &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;&quot;#CCFF99&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt; } &lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt; else&lt;/span&gt;
  tbl&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rows&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;j&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;style&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;display &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;&quot;none&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;

&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;window&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;onload&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;collapseRows&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;

&lt;/pre&gt;
&lt;div style=&quot;float: left; margin: 2px 4px;&quot;&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
google_ad_client = &quot;ca-pub-8504512626105280&quot;;
/* 300x250, created 12/9/10 */
google_ad_slot = &quot;7115539031&quot;;
google_ad_width = 300;
google_ad_height = 250;
//--&gt;
&lt;/script&gt;&lt;script src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;&lt;/div&gt;
Let me briefly explain what the script does. When a page has loaded, the &lt;span style=&quot;font-weight: bold;&quot;&gt;collapseRows&lt;/span&gt; function is called. It looks for a table with a class named &#39;&lt;span style=&quot;font-weight: bold;&quot;&gt;expandable&lt;/span&gt;&#39;. If such a table is found, a reference to the table is stored in a variable &lt;span style=&quot;font-weight: bold;&quot;&gt;tbl&lt;/span&gt;, and the number of rows in the table is stored in a variable &lt;span style=&quot;font-weight: bold;&quot;&gt;len&lt;/span&gt;.&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;var len = tbl.rows.length;&lt;/code&gt;&lt;br /&gt;
Then, we create a variable that holds an html link that will call the &lt;span style=&quot;font-weight: bold;&quot;&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=&quot;font-weight: bold;&quot;&gt;this&lt;/span&gt; keyword here.&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;var&lt;/span&gt; link &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;&#39;&amp;lt;a href=&quot;#&quot; onclick=&quot;toggleSection(this);return false;&quot;&amp;gt;+ &amp;lt;/a&amp;gt; &#39;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&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;/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=&quot;color: blue; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;j&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt; j &lt;span style=&quot;color: black;&quot;&gt;&amp;lt;&lt;/span&gt; len&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;j&lt;span style=&quot;color: black;&quot;&gt;++){&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt; var&lt;/span&gt; m &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; tbl&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rows&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;j&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;cells&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;innerHTML&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt; if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;m&lt;span style=&quot;color: black;&quot;&gt;!=&lt;/span&gt;rowHead &lt;span style=&quot;color: black;&quot;&gt;||&lt;/span&gt; j&lt;span style=&quot;color: black;&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;){&lt;/span&gt;
  rowHead&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt;m&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
  tbl&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rows&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;j&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;cells&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;innerHTML&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; link&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
  tbl&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rows&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;j&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;style&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;background &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;&quot;#CCFF99&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt; }&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt; else&lt;/span&gt;
  tbl&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rows&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;j&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;style&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;display &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;&quot;none&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;

&lt;/pre&gt;
The next function, &lt;span style=&quot;font-weight: bold;&quot;&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=&quot;color: blue; font-weight: bold;&quot;&gt;var&lt;/span&gt; td &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; lnk&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;parentNode&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;var&lt;/span&gt; tr &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;getParent&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;td&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;&#39;tr&#39;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;var&lt;/span&gt; rowIndex &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; tr&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rowIndex&lt;span style=&quot;color: black;&quot;&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;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 == &quot;+&quot;)?&quot;-&quot;:&quot;+&quot;;&lt;br /&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==&#39;none&#39;)?&#39;&#39;:&#39;none&#39;;&lt;br /&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;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;var&lt;/span&gt; i &lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; rowIndex&lt;span style=&quot;color: black;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt; i &lt;span style=&quot;color: black;&quot;&gt;&amp;lt;&lt;/span&gt; len&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;i&lt;span style=&quot;color: black;&quot;&gt;++){&lt;/span&gt;
&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;table&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rows&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;i&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;cells&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;&lt;span style=&quot;color: blue; font-weight: bold;&quot;&gt;innerHTML&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;==&lt;/span&gt;rowHead&lt;span style=&quot;color: black;&quot;&gt;){&lt;/span&gt;
 table&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;rows&lt;span style=&quot;color: black;&quot;&gt;[&lt;/span&gt;i&lt;span style=&quot;color: black;&quot;&gt;].&lt;/span&gt;style&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;display&lt;span style=&quot;color: black;&quot;&gt;=&lt;/span&gt; vStyle&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&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=&quot;hidden&quot;;&lt;br /&gt;
&lt;br /&gt;
Don&#39;t forget, the table must contain an empty first column to hold a plus or minus sign and have a class named &#39;&lt;span style=&quot;font-weight: bold;&quot;&gt;expandable&lt;/span&gt;&#39;.&lt;br /&gt;
&lt;br /&gt;
See a demo &lt;a href=&quot;http://js-code.blogspot.com/p/table-tr-td-th-border-stylesolid-border.html&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
The script can be downloaded &lt;a href=&quot;http://cyrillic-encoder.googlecode.com/files/expand_rows.js&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Another&amp;nbsp;post&amp;nbsp;dealing with the HTML table :&lt;br /&gt;
&lt;a href=&quot;http://js-code.blogspot.ca/2011/05/simple-way-to-highlight-table-cells.html&quot;&gt;Highlight Table Cells with JavaScript &lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/code&gt;&amp;nbsp;&lt;/code&gt;&amp;nbsp;&lt;/code&gt;&amp;nbsp;&lt;/code&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='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/1612136084042548487'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2885018062563133508/posts/default/1612136084042548487'/><link rel='alternate' type='text/html' href='http://js-code.blogspot.com/2009/03/expandcollapse-rows-dynamically-with.html' title='Expand/Collapse Rows Dynamically with DOM and JavaScript'/><author><name>Erik K.</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='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5jqsuvFXluNfkKboo2YBXgoT7y0FeTRYM5VhisbGNzrlKSAOu9DeVXbDc4wlX7PR_avzEYvLF933F7PQsoYGPZ6TQegGxOfW4uiGMT2F36j9thJCCQf1vEF7QywYxQ00G2PCS-IW3cK0/s72-c/table1.JPG" height="72" width="72"/><thr:total>7</thr:total></entry></feed>