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

<channel>
	<title>Code Zhandwa</title>
	<atom:link href="http://code.zhandwa.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://code.zhandwa.com</link>
	<description>Seriously dude, don't ask!</description>
	<pubDate>Sat, 10 Jan 2009 17:28:09 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Moved!</title>
		<link>http://code.zhandwa.com/2009/01/10/moved/</link>
		<comments>http://code.zhandwa.com/2009/01/10/moved/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 17:28:09 +0000</pubDate>
		<dc:creator>zhandwa</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://code.zhandwa.com/?p=117</guid>
		<description><![CDATA[I have moved to a new domain. This site is now located at : http://brokenshard.in/tech.
See you there&#8230;.
I am leaving this blog up, cause its linked from quite some places.  
]]></description>
			<content:encoded><![CDATA[<p>I have moved to a new domain. This site is now located at : <a href="http://brokenshard.in/tech">http://brokenshard.in/tech</a>.</p>
<p>See you there&#8230;.</p>
<p><em>I am leaving this blog up, cause its linked from quite some places. <img src='http://code.zhandwa.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </em></p>
<div id="st2008071517" class="st-taf"><script src="http://tellafriend.socialtwist.com:80/wizard/js/shoppr.core.js?id=2008071517"></script><img style="border:0;" src="http://tellafriend.socialtwist.com:80/wizard/getButton.jsp?id=2008071517" onmouseout="hideHoverMap(this)" onmouseover="showHoverMap(this, '2008071517',  'http%3A%2F%2Fcode.zhandwa.com%2F2009%2F01%2F10%2Fmoved%2F', 'Moved%21')" onclick="cw(this, {id:'2008071517',link: 'http%3A%2F%2Fcode.zhandwa.com%2F2009%2F01%2F10%2Fmoved%2F', title: '+Moved%21+' })"/></div>]]></content:encoded>
			<wfw:commentRss>http://code.zhandwa.com/2009/01/10/moved/feed/</wfw:commentRss>
		</item>
		<item>
		<title>jQuery track changes plugin updated</title>
		<link>http://code.zhandwa.com/2008/12/31/jquery-track-changes-plugin-updated/</link>
		<comments>http://code.zhandwa.com/2008/12/31/jquery-track-changes-plugin-updated/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 20:00:20 +0000</pubDate>
		<dc:creator>zhandwa</dc:creator>
		
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://code.zhandwa.com/?p=115</guid>
		<description><![CDATA[Just fixed a small issue with the plugin which was causing it to fail on Internet Explorer. Thanks to all of you who pointed that out.  
Download and Demo on the jQuery page.
]]></description>
			<content:encoded><![CDATA[<p>Just fixed a small issue with the plugin which was causing it to fail on Internet Explorer. Thanks to all of you who pointed that out. <img src='http://code.zhandwa.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><a title="jQuery page" href="http://code.zhandwa.com/jquery/" target="_blank">Download and Demo</a> on the jQuery page.</p>
<div id="st2008071517" class="st-taf"><script src="http://tellafriend.socialtwist.com:80/wizard/js/shoppr.core.js?id=2008071517"></script><img style="border:0;" src="http://tellafriend.socialtwist.com:80/wizard/getButton.jsp?id=2008071517" onmouseout="hideHoverMap(this)" onmouseover="showHoverMap(this, '2008071517',  'http%3A%2F%2Fcode.zhandwa.com%2F2008%2F12%2F31%2Fjquery-track-changes-plugin-updated%2F', 'jQuery+track+changes+plugin+updated')" onclick="cw(this, {id:'2008071517',link: 'http%3A%2F%2Fcode.zhandwa.com%2F2008%2F12%2F31%2Fjquery-track-changes-plugin-updated%2F', title: '+jQuery+track+changes+plugin+updated+' })"/></div>]]></content:encoded>
			<wfw:commentRss>http://code.zhandwa.com/2008/12/31/jquery-track-changes-plugin-updated/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Learning the Web</title>
		<link>http://code.zhandwa.com/2008/08/28/learning-the-web/</link>
		<comments>http://code.zhandwa.com/2008/08/28/learning-the-web/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 17:58:12 +0000</pubDate>
		<dc:creator>zhandwa</dc:creator>
		
		<category><![CDATA[know-how]]></category>

		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://code.zhandwa.com/?p=94</guid>
		<description><![CDATA[What would you do, if you are asked to teach someone Web Development? JavaScript, HTML and all. I recently faced such a situation and thought it would be nice to share what I came up with.

Start with w3schools
There is no better place to begin than w3schools. I used it myself, and I still go there [...]]]></description>
			<content:encoded><![CDATA[<p>What would you do, if you are asked to teach someone Web Development? JavaScript, HTML and all. I recently faced such a situation and thought it would be nice to share what I came up with.</p>
<ol>
<li><strong>Start with w3schools</strong></li>
<p>There is no better place to begin than <a href="http://www.w3schools.com">w3schools</a>. I used it myself, and I still go there every now and then to reference something or the other. The tutorials are designed for the absolute beginners and explain every section in just the right way. It&#8217;s the first place I recommend anybody to start with who wants to learn about web development. Considering that web development in today&#8217;s world is not as vanilla as it used to be - I would begin with the following on w3schools:</p>
<ul>
<li>HTML -&gt; DOM -&gt; CSS -&gt; JavaScript</li>
</ul>
<p>HTML is again the most obvious. Knowing the DOM is next as you will probably be using it the most in JavaScript. CSS is critical to know because most web 2.0/AJAX stuff requires you to manipulate CSS via JavaScript.<br />
<br/><br />
One thing to remember here is not to do any assignments other than the ones present on w3schools. Even looking at any assignments beforehand will make you think about them and you may end up skipping some topics, which can come back to haunt you later. Trust me on this one.</p>
<li><strong>Create a website</li>
<p></strong>Yeah. There is no better way to learn than to start experiencing. So, I would recommend you make a simple site. Nothing fancy. A simple, 2 column  website with links on the left and content on the right - and do this using only CSS and HTML. No JavaScript should be used here and don&#8217;t use tables for layouts. <img src='http://code.zhandwa.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<li><strong>Mod the website with JavaScript</strong></li>
<p>Make the links on the left fade in and fade out. This will enable you understand CSS manipulation and JavaScript timeout features. From this point onwards everything in the site should be added via JavaScript. Creating almost every single HTML element in the page using JavaScript will enable a good hold on DOM parsing, attaching events, etc.</p>
<li><strong>Get the Holy Grail</strong></li>
<p>Time has come to get the holy grail of web development. Install <a href="http://www.mozilla.com/firefox/">Mozilla Firefox</a> followed by <a href="https://addons.mozilla.org/firefox/addon/1843">Firebug</a>. Open up the website you just created and use Firebug&#8217;s <strong>inspect</strong> tool to inspect your HTML code. Put a breakpoint in your JavaScript code and see how the DOM looks. Use <strong>watch expression</strong> to check out how JavaScript behaves.Firebug is probably the best way to understand what you learnt in Step 1, 2 and 3. It will provide you with details of how the DOM looks like, how JavaScript behaves and what objects contain which attributes and properties.</p>
<li><strong>Back to w3schools</strong></li>
<p>Go back and learn the AJAX tutorial. Understand how it works across browsers. Use Firebug to see how request are made in the background and how the response comes back. Here you may slow down and also look at how HTTP headers look like. If you want to indulge deeper, you may as well read more about them.</p>
<li><strong>Convert your website into an AJAX powerhouse</strong></li>
<p>Whatever you designed in step 3, should now be AJAX-ified. Convert all link clicks to load content on the right pane using AJAX. No page refreshes and show a proper loading icon when an AJAX request is made.</p>
<li><strong>JSON</strong></li>
<p>This may not be an absolute requirement, but I would say you learn it right now. JSON is the preferred response type in most AJAX calls, so understanding how it looks and behaves is extremely important from a long term perspective.Convert your AJAX responses from Step 6 to return JSON objects. Parse them and show your content. modify your content to have multiple headings and paragraphs.</p>
<li><strong>More Assignments</strong></li>
<p>This is the time I would really start doing some hardcore coding. I usually ask people to extend on what they have already done:</p>
<ul>
<li>Create a fluid three column layout with a header and footer - which works across all browsers.</li>
<li>Put some links in the left panel, the right panel and the footer.</li>
<li>Create navigation controls in the left panel using unordered lists and CSS.</li>
<li>Use JavaScript Timeouts and CSS to animate the navigation panel.</li>
<li>Make all clicks on the navigation panel load complex data through AJAX and JSON.</li>
<li>A search box at the top of the navigation panel should filter the links in the panel, as you type.</li>
<li>Clicking any links in the footer should open a popup inside the same page - positioned dead center of the page. Turn the background gray. - ala Lightbox type effect. No popup windows.
<li>Clicking any link on the right panel should open actual popup windows.</li>
<li>Try loading content from a different domain using AJAX calls (Cross Domain Issues and Scripting).</li>
</ul>
<p><br/></p>
<li><strong>Pick up a JavaScript library</strong></li>
<p>The last thing is to pick up a JavaScript library, if you are allowed to ;). In my case the requirement was of jQuery (thankfully). Check it out and then redo all the previous steps using the Javascript library/framework.
</ol>
<p>As of now, I don&#8217;t know how effective this would be to get somebody started with. I will keep updating this post, each time I think that I shouldn&#8217;t have done that. <img src='http://code.zhandwa.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<div id="st2008071517" class="st-taf"><script src="http://tellafriend.socialtwist.com:80/wizard/js/shoppr.core.js?id=2008071517"></script><img style="border:0;" src="http://tellafriend.socialtwist.com:80/wizard/getButton.jsp?id=2008071517" onmouseout="hideHoverMap(this)" onmouseover="showHoverMap(this, '2008071517',  'http%3A%2F%2Fcode.zhandwa.com%2F2008%2F08%2F28%2Flearning-the-web%2F', 'Learning+the+Web')" onclick="cw(this, {id:'2008071517',link: 'http%3A%2F%2Fcode.zhandwa.com%2F2008%2F08%2F28%2Flearning-the-web%2F', title: '+Learning+the+Web+' })"/></div>]]></content:encoded>
			<wfw:commentRss>http://code.zhandwa.com/2008/08/28/learning-the-web/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Simple twist to the unobtrusive anti-spam technique</title>
		<link>http://code.zhandwa.com/2008/08/25/simple-twist-to-the-unobtrusive-anti-spam-technique/</link>
		<comments>http://code.zhandwa.com/2008/08/25/simple-twist-to-the-unobtrusive-anti-spam-technique/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 15:25:59 +0000</pubDate>
		<dc:creator>zhandwa</dc:creator>
		
		<category><![CDATA[scripts]]></category>

		<category><![CDATA[anti-spam]]></category>

		<category><![CDATA[forms]]></category>

		<category><![CDATA[html]]></category>

		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://code.zhandwa.com/?p=87</guid>
		<description><![CDATA[Update: As Alex mentioned in the comments, the following approach that I have mentioned is actually obtrusive.  
I was going through this excellent blog post explaining a simple way to avoid bot based spamming.
Well the idea is relatively simple: Add CSS-hidden fields that a user won&#8217;t see, but a spam-bot will fill. Then using [...]]]></description>
			<content:encoded><![CDATA[<p><em>Update: As Alex mentioned in the comments, the following approach that I have mentioned is actually obtrusive. <img src='http://code.zhandwa.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </em></p>
<p>I was going through this excellent <a href="http://urbanoalvarez.es/blog/2008/08/23/best-unobtrusive-anti-spam-technique-not-captcha/" target="_blank">blog post</a> explaining a simple way to avoid bot based spamming.</p>
<blockquote><p><em>Well the idea is relatively simple: Add <a href="http://en.wikipedia.org/wiki/Cascading_Style_Sheets">CSS</a>-hidden fields that a user won&#8217;t see, but a spam-bot will fill. Then using <a href="http://www.php.net/">php</a> check if they were filled, and if they were: block the spammer!</em></p></blockquote>
<p>The idea by itself is good, but then I thought that it won&#8217;t be very hard for bots to filter out such hidden fields. As a matter of fact, input fields which are hidden or even those which have negative margins are not all that difficult to detect and skip.</p>
<p>Then I thought, instead of hiding the field, it will be difficult for a bot to skip/filter a field which sounds very authentic, is actually visible, but should validate to not hold a value? A user would read the label and understand that he/she is not supposed to enter anything in this field, but a bot would go ahead and fill out the field.</p>
<p>So a basic form would look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submitForm&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span>&gt;</span>
    Name: <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;username&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;username&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
    Email Id: <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
    Please do not enter anything in this field: <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;emailID&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;emailID&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<div id="st2008071517" class="st-taf"><script src="http://tellafriend.socialtwist.com:80/wizard/js/shoppr.core.js?id=2008071517"></script><img style="border:0;" src="http://tellafriend.socialtwist.com:80/wizard/getButton.jsp?id=2008071517" onmouseout="hideHoverMap(this)" onmouseover="showHoverMap(this, '2008071517',  'http%3A%2F%2Fcode.zhandwa.com%2F2008%2F08%2F25%2Fsimple-twist-to-the-unobtrusive-anti-spam-technique%2F', 'Simple+twist+to+the+unobtrusive+anti-spam+technique')" onclick="cw(this, {id:'2008071517',link: 'http%3A%2F%2Fcode.zhandwa.com%2F2008%2F08%2F25%2Fsimple-twist-to-the-unobtrusive-anti-spam-technique%2F', title: '+Simple+twist+to+the+unobtrusive+anti-spam+technique+' })"/></div>]]></content:encoded>
			<wfw:commentRss>http://code.zhandwa.com/2008/08/25/simple-twist-to-the-unobtrusive-anti-spam-technique/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Tools for the developer on steroids: Super fast launchers</title>
		<link>http://code.zhandwa.com/2008/08/18/tools-for-the-developer-on-steroids-super-fast-launchers/</link>
		<comments>http://code.zhandwa.com/2008/08/18/tools-for-the-developer-on-steroids-super-fast-launchers/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 12:08:58 +0000</pubDate>
		<dc:creator>zhandwa</dc:creator>
		
		<category><![CDATA[software]]></category>

		<category><![CDATA[autocomplete]]></category>

		<category><![CDATA[launchers]]></category>

		<category><![CDATA[launchy]]></category>

		<category><![CDATA[slickrun]]></category>

		<guid isPermaLink="false">http://code.zhandwa.com/?p=69</guid>
		<description><![CDATA[This post is for Windows users only.
I absolutely love those auto-completing, always-remembering launcher applications. I have been using them for ages now. It has also made its way into Vista&#8217;s start menu, but there is so much more that a launcher should do.
The first launcher application that I used, and still do is LSXCommand. Its [...]]]></description>
			<content:encoded><![CDATA[<div class="notice"><strong><em>This post is for Windows users only.</em></strong></div>
<p>I absolutely love those auto-completing, always-remembering launcher applications. I have been using them for ages now. It has also made its way into Vista&#8217;s start menu, but there is so much more that a launcher should do.</p>
<p>The first launcher application that I used, and still do is <a href="http://www.xdocs.ls-universe.info/pie.php?LSXCommand" target="_blank">LSXCommand</a>. Its a module for the alternative windows shell called <a href="http://www.litestep.net/" target="_blank">LiteStep</a>. I will not write about it here because it requires you to ditch your windows look and feel and switch to <a href="http://www.ls-universe.info/news.php" target="_blank">LiteStep</a>. So, when I did not have that option, I started my search for an alternative windows only application which is fast, simple, takes really less real estate and well - does the job.</p>
<p>I came across <a href="http://www.launchy.net/" target="_blank">Launchy</a>, used it for quite some time, and its great. It even made me an alt+space junkie. <a href="http://www.launchy.net/" target="_blank">Launchy</a> indexes the start menu, or any other folder I want, with whatever extensions I want as well.</p>
<p style="text-align: center;"><a title="Launchy" href="http://www.launchy.net/" target="_blank"><img class="aligncenter" src="http://code.zhandwa.com/wp-content/uploads/2008/08/capture-lan.jpg" alt="Launchy" /></a></p>
<p>It looks amazing, has a lot of skins available and we have the option to add custom commands. After using it for a while, I realized that Start Menu indexing is something that I hardy used. It kinda makes Launchy eat more resources while most of my work was around my custom defined commands.</p>
<p>As always when I started getting bored of Launchy, I started my search again and came across <a href="http://www.bayden.com/SlickRun/" target="_blank">SlickRun</a>. An even more lightweight launcher which is a lot similar to LSXCommand.</p>
<p style="text-align: center;"><a title="SlickRun" href="http://www.bayden.com/SlickRun/" target="_blank"><img class="aligncenter" src="http://code.zhandwa.com/wp-content/uploads/2008/08/capture-slick.jpg" alt="SlickRun" /></a></p>
<p>It does everything that other launchers do, but <strong>does not index</strong> any folders - which is precisely what I was looking for. Custom commands can be added as MagicWords, which can take parameters for dynamic content as well. I configured it to my alt+space hot key, added all my magic words and have never since looked for another launcher.</p>
<p>So, if you prefer the keyboard over the mouse, and are constantly using the Vista Start Menu or the good old Windows Run option, give one of these launchers a shot. You will absolutely love it! <img src='http://code.zhandwa.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Next up: Organize your files with a better file manager.</p>
<div id="st2008071517" class="st-taf"><script src="http://tellafriend.socialtwist.com:80/wizard/js/shoppr.core.js?id=2008071517"></script><img style="border:0;" src="http://tellafriend.socialtwist.com:80/wizard/getButton.jsp?id=2008071517" onmouseout="hideHoverMap(this)" onmouseover="showHoverMap(this, '2008071517',  'http%3A%2F%2Fcode.zhandwa.com%2F2008%2F08%2F18%2Ftools-for-the-developer-on-steroids-super-fast-launchers%2F', 'Tools+for+the+developer+on+steroids%3A+Super+fast+launchers')" onclick="cw(this, {id:'2008071517',link: 'http%3A%2F%2Fcode.zhandwa.com%2F2008%2F08%2F18%2Ftools-for-the-developer-on-steroids-super-fast-launchers%2F', title: '+Tools+for+the+developer+on+steroids%3A+Super+fast+launchers+' })"/></div>]]></content:encoded>
			<wfw:commentRss>http://code.zhandwa.com/2008/08/18/tools-for-the-developer-on-steroids-super-fast-launchers/feed/</wfw:commentRss>
		</item>
		<item>
		<title>7 things to remember while building a web application - Part I</title>
		<link>http://code.zhandwa.com/2008/08/11/7-things-to-remember-while-building-a-web-application-part-i/</link>
		<comments>http://code.zhandwa.com/2008/08/11/7-things-to-remember-while-building-a-web-application-part-i/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 16:18:36 +0000</pubDate>
		<dc:creator>zhandwa</dc:creator>
		
		<category><![CDATA[code-ramblings]]></category>

		<category><![CDATA[browsers]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://code.zhandwa.com/?p=51</guid>
		<description><![CDATA[Don&#8217;t we all love building applications for the web. From the mundane page by page browsing, web development has come a long way - thanks to the web 2.0 mania. Building anything on the web these days require a good amount of HTML and CSS knowledge. Gone are those times when the &#8220;programmers&#8221; build the [...]]]></description>
			<content:encoded><![CDATA[<p>Don&#8217;t we all love building applications for the web. From the mundane page by page browsing, web development has come a long way - thanks to the web 2.0 mania. Building anything on the web these days require a good amount of HTML and CSS knowledge. Gone are those times when the &#8220;programmers&#8221; build the application and the UI folks plug it in. Most web based applications are Javascript intensive, which tag along a lot of CSS manipulation. And to top it all we have atleast 4 major browsers to support - one of which is a major pain in the ass.</p>
<p>The following things top my list of &#8220;remember-or-get-hurt&#8221;:</p>
<ol>
<li>
<strong>Always specify a DOCTYPE</strong></p>
<p>I cannot tell you how much pain and misery <strong>not</strong> doing this would cause your development process. At one point we ended up writing completely different sets of CSS files for different browsers! - all because someone (read me) forgot to mention the document DOCTYPE. Here is a <a title="A List Apart - DOCTYPE" href="http://www.alistapart.com/stories/doctype/" target="_blank">link to an ALA article</a> if you want to know more.</p>
</li>
<li><strong>Never code for Firefox</strong>
<p>Okay this is a personal thing. Thanks to <a title="Firebug Addons" href="https://addons.mozilla.org/en-US/firefox/addon/1843" target="_blank">Firebug</a>, we love developing on <a title="The next best thing to - Opera! :p" href="http://www.mozilla.com/en-US/firefox/" target="_blank">Firefox</a>. Its incredibly easy to work on and it probably has the best development tools to boot. <a title="Yahoo's YSlow" href="http://developer.yahoo.com/yslow/" target="_blank">YSlow</a>, dozens of FireBug extensions, <a title="Live HTTP Headers" href="https://addons.mozilla.org/en-US/firefox/addon/3829" target="_blank">Live HTTP Headers</a>, etc etc. All said and done, you still need to support the other evil - Internet Explorer. After all, 70% of the world still uses it - don&#8217;t ask me why!. During development, it is wise to have both <a title="The next best thing to - Opera! :p" href="http://www.mozilla.com/en-US/firefox/" target="_blank">Firefox</a> and IE running. I know a few CSS dudes who would never ever develop just for <a title="The next best thing to - Opera! :p" href="http://www.mozilla.com/en-US/firefox/" target="_blank">Firefox</a>. They will always have IE, <a title="The next best thing to - Opera! :p" href="http://www.mozilla.com/en-US/firefox/" target="_blank">Firefox</a> and Safari open at all times. It&#8217;s always easier to check first than fix later.
</p>
<p>Here are some tools that will ease your development on IE: (Just Google them for links. Too lazy. ;))</p>
<ul>
<li>Debug Bar</li>
<li>Web Inspector</li>
<li>IE HTTP Headers</li>
<li>IE Web Developer Toolbar</li>
<li>Firebug Lite</li>
<li>Visual Studio Debugger</li>
</ul>
</li>
<p>
<li><strong>Hacks are quick solutions, but better if avoided</strong></p>
<p>Hacks. Well usually this means - workarounds. It sometimes also means, things you need to do to please the evil goddess of IE. By now there are about a gazillion different hacks to make things work in IE - give or take one or two. They all work, but make maintainability a major issue. Moreover you never know IE8 could actually be good when it comes to standards. Or if you do use browser specific hacks, please make sure you put appropriate comments and don&#8217;t just write <a title="Code Commenting!" href="http://www.codinghorror.com/blog/archives/001150.html" target="_blank">understandable code.</a> :p
</p>
</li>
<li><strong>Don&#8217;t use AJAX everywhere</strong>
<p>
XHR calls and funky loading animations add that web 2.0 zing to your application, but don&#8217;t overdo them. With AJAX/XHR come a lot more lines of code in order to implement bookmarking, the back button, the page refreshes, etc etc. XHR will definitely speed up your page loads and will definitely make it look cool - but make sure you keep important pages of your application with linkable, bookmarkable URLs. And it would be better if doing this does not require a lot of JavaScript code.
</p>
</li>
<li><strong>Graceful degradation</strong>
<p>This is another thing that a developer should keep in mind. What would happen to my application if the browser does not support JavaScript - or rather, if the user has disabled JavaScript? Agreed, this is a hard-to-come-by scenario and probably anybody using a web 2.0 website would never have JavaScript disabled, but it is something one should spare some time on. Your application should at least be &#8220;readable&#8221; when JavaScript is disabled. It need not be fully functional. Most new age JS frameworks are unobtrusive and degrade gracefully, but make sure your code does too.</p>
</li>
<li><strong>Not everybody is on freaking Broadband</strong>
<p>
Yes, you heard it right. Don&#8217;t bloat your pages. Don&#8217;t clutter them. And for heaven&#8217;s sake don&#8217;t put videos, flash animations, big images all on one page. People designing websites which expect heavy traffic, go miles to ensure that their pages load fast. HTTP requests are minimal, external JS and CSS files are minimized. Interfaces which are light, load fast and are free of clutter are always better - even if this means sacrificing that cool gfx or Flash/JS effect. Yahoo&#8217;s performance benchmarks and YSlow are good to start with.
</p>
</li>
<li><strong>Ditch support for IE6</strong>
<p>This is my personal favorite. Just decide not to support IE6. It&#8217;s release was probably the biggest mistake anyway. Supporting it will result in countless hours of frustration and an end result which will be less than satisfying. I know a lot of people use IE6, but as I said, I personally will never build support for it. And I am not the <a title="37Signals" href="http://37signals.blogs.com/products/2008/07/basecamp-phasin.html" target="_blank">only</a> <a title="MobileMe" href="http://www.37signals.com/svn/posts/1072-apples-mobileme-drops-support-for-ie-6" target="_blank">one</a>. (I know it ain&#8217;t a very bright idea while developing commercial web applications, but hey!, a developer has to have his say at some point ;))
</p>
</li>
</ol>
<p>
These were some very basic points to keep in mind while making a web based application - all on the client side though. Part II will feature things that one needs to take care of on the server side. Keep watching this space. <img src='http://code.zhandwa.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div id="st2008071517" class="st-taf"><script src="http://tellafriend.socialtwist.com:80/wizard/js/shoppr.core.js?id=2008071517"></script><img style="border:0;" src="http://tellafriend.socialtwist.com:80/wizard/getButton.jsp?id=2008071517" onmouseout="hideHoverMap(this)" onmouseover="showHoverMap(this, '2008071517',  'http%3A%2F%2Fcode.zhandwa.com%2F2008%2F08%2F11%2F7-things-to-remember-while-building-a-web-application-part-i%2F', '7+things+to+remember+while+building+a+web+application+-+Part+I')" onclick="cw(this, {id:'2008071517',link: 'http%3A%2F%2Fcode.zhandwa.com%2F2008%2F08%2F11%2F7-things-to-remember-while-building-a-web-application-part-i%2F', title: '+7+things+to+remember+while+building+a+web+application+-+Part+I+' })"/></div>]]></content:encoded>
			<wfw:commentRss>http://code.zhandwa.com/2008/08/11/7-things-to-remember-while-building-a-web-application-part-i/feed/</wfw:commentRss>
		</item>
		<item>
		<title>New browser on the block? - Sleipnir</title>
		<link>http://code.zhandwa.com/2008/08/04/new-browser-on-the-block-sleipnir/</link>
		<comments>http://code.zhandwa.com/2008/08/04/new-browser-on-the-block-sleipnir/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 16:46:47 +0000</pubDate>
		<dc:creator>zhandwa</dc:creator>
		
		<category><![CDATA[software]]></category>

		<category><![CDATA[browsers]]></category>

		<category><![CDATA[new software]]></category>

		<guid isPermaLink="false">http://code.zhandwa.com/?p=46</guid>
		<description><![CDATA[Recently I came across this new browser - Sleipnir. It ain&#8217;t totally new, as it&#8217;s been used by 6% of Japan for quite some time now. Just new for us folks, who don&#8217;t know much about Japanese stuff except for maybe the horror movies.  
I came across Sleipnir, and the thing that immediately caught [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I came across this new browser - <a title="Sleipnir's Global Site" href="http://www.fenrir-inc.com/" target="_blank">Sleipnir</a>. It ain&#8217;t totally new, as it&#8217;s been <a title="wiki!" href="http://en.wikipedia.org/wiki/Sleipnir_(web_browser)" target="_blank">used by 6% of Japan</a> for quite some time now. Just new for us folks, who don&#8217;t know much about Japanese stuff except for maybe the horror movies. <img src='http://code.zhandwa.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>I came across <a title="Sleipnir's Global Site" href="http://www.fenrir-inc.com/" target="_blank">Sleipnir</a>, and the thing that immediately caught my eye was support for both the Internet Explorer Trident engine as well as the Gecko engine used by Firefox. This effectively gives you native support for both engines, without actually using an extension like IE-Tab for Firefox.</p>
<p>But the question is what else does this &#8220;new&#8221; browser bring with it? Or rather, what are the features that make this browser stand apart? Once you install the browser and run it, you will be surprised as to how strikingly similar <a title="Sleipnir's Global Site" href="http://www.fenrir-inc.com/" target="_blank">Sleipnir</a> is to the IE6 interface. That BTW, sent chills down my spine. But, that is a different story.</p>
<div id="attachment_47" class="wp-caption aligncenter" style="width: 310px"><a href="http://code.zhandwa.com/wp-content/uploads/2008/08/capture-sl-1.jpg"><img class="size-medium wp-image-47" title="Sleipnir" src="http://code.zhandwa.com/wp-content/uploads/2008/08/capture-sl-1-300x214.jpg" alt="The interface" width="300" height="214" /></a><p class="wp-caption-text">The interface</p></div>
<p>The second thing that one notices while using this Japanese browser is the text. The English looks pretty messed up, and at times it is really hard to understand what a feature is supposed to do. Documentation is hard to find, and certain things are just not clear enough to make sense. There is an extensive support section available now, but as I said, not very helpful. A lot of effort is put in, but the English needs a lot of tweaking.</p>
<p>The browser looks to be customizable in every possible aspect. Themes/Skins and plug-ins are available on the home page and in all it doesn&#8217;t look half bad.</p>
<p>The thing I wanted to check out personally was how good is this browser when it comes to web development. Is there something like Firebug? A firebug like tool integrated alongside support for IE would totally rock. And quite surprisingly there is an extension called <a title="Hawkeye" href="http://www.fenrir-inc.com/us/sleipnir/plugins/hawkeye.html" target="_blank">Hawkeye</a> available for download from the <a title="Plugins page" href="http://www.fenrir-inc.com/us/sleipnir/plugins/" target="_blank">Sleipnir plug-ins download page</a>.</p>
<div id="attachment_48" class="wp-caption aligncenter" style="width: 310px"><a href="http://code.zhandwa.com/wp-content/uploads/2008/08/capture-2-slep.jpg"><img class="size-medium wp-image-48" title="Hawkeye" src="http://code.zhandwa.com/wp-content/uploads/2008/08/capture-2-slep-300x214.jpg" alt="Sleipnir's web dev tool" width="300" height="214" /></a><p class="wp-caption-text">Sleipnir&#39;s web dev tool</p></div>
<p>It is no Firebug killer, but provides enough features for you get started with. Apart from the most obvious firebug like options, some features like the various display options (color information, size of divs, etc) are nice and really helpful to have.</p>
<p><a title="Sleipnir's USA Site" href="http://www.fenrir-inc.com/us/sleipnir/" target="_blank">Sleipnir</a> is a good browser. It has a long way to go before it is accepted in the English market, but it definitely has the goods to be a great browser. For the time being though, I am not thinking of switching away from the comfort of FireFox or the better - Opera. <img src='http://code.zhandwa.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<div id="st2008071517" class="st-taf"><script src="http://tellafriend.socialtwist.com:80/wizard/js/shoppr.core.js?id=2008071517"></script><img style="border:0;" src="http://tellafriend.socialtwist.com:80/wizard/getButton.jsp?id=2008071517" onmouseout="hideHoverMap(this)" onmouseover="showHoverMap(this, '2008071517',  'http%3A%2F%2Fcode.zhandwa.com%2F2008%2F08%2F04%2Fnew-browser-on-the-block-sleipnir%2F', 'New+browser+on+the+block%3F+-+Sleipnir')" onclick="cw(this, {id:'2008071517',link: 'http%3A%2F%2Fcode.zhandwa.com%2F2008%2F08%2F04%2Fnew-browser-on-the-block-sleipnir%2F', title: '+New+browser+on+the+block%3F+-+Sleipnir+' })"/></div>]]></content:encoded>
			<wfw:commentRss>http://code.zhandwa.com/2008/08/04/new-browser-on-the-block-sleipnir/feed/</wfw:commentRss>
		</item>
		<item>
		<title>jQuery: Track changes in your forms</title>
		<link>http://code.zhandwa.com/2008/07/31/jquery-track-changes-in-your-forms/</link>
		<comments>http://code.zhandwa.com/2008/07/31/jquery-track-changes-in-your-forms/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 15:46:25 +0000</pubDate>
		<dc:creator>zhandwa</dc:creator>
		
		<category><![CDATA[scripts]]></category>

		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://code.zhandwa.com/?p=26</guid>
		<description><![CDATA[Update: This plugin has been updated. Please follow this link for the updated plugin information, demo and download.
While working on an assignment, I came up with this small, useful plugin which would allow you to track changes in your forms. The idea was to ensure that a user can only save changes, if he or [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong>: <strong>This plugin has been updated. Please follow <a title="jQuery Page" href="http://code.zhandwa.com/jquery/" target="_blank">this link</a> for the updated plugin information, demo and download.</strong></p>
<p>While working on an <a title="Tell-a-Friend" href="http://tellafriend.socialtwist.com" target="_blank">assignment</a>, I came up with this small, useful plugin which would allow you to track changes in your forms. The idea was to ensure that a user can only save changes, if he or she has made any. Once a form is loaded, with the previously saved values or the default values, any changes made to the form fields will become part of a list which will be passed on when the form is submitted.</p>
<p>The basic usage is as follows:</p>
<p>On document ready, add &#8220;trackChanges&#8221; to the form you want to be tracked:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">    <span style="color: #006600; font-style: italic;">// only events</span>
    <span style="color: #003366; font-weight: bold;">var</span> oldvals1 <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#form1'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">trackChanges</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>events<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;change blur keypress keydown click&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #006600; font-style: italic;">// all the options</span>
    <span style="color: #003366; font-weight: bold;">var</span> oldvals3 <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#form3'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">trackChanges</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
          changeListName<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;form3List&quot;</span><span style="color: #339933;">,</span>  <span style="color: #006600; font-style: italic;">// changed field names will be in this list (if not given defaults to {formname}TrackList)</span>
          events<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;change blur keypress keydown click&quot;</span><span style="color: #339933;">,</span>  <span style="color: #006600; font-style: italic;">// events on which the tracking should occur</span>
          changeListVisible<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// should the change list be visible</span>
          changeListClass<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;custom&quot;</span> <span style="color: #006600; font-style: italic;">// css class applied to the change list</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>You can download an experimental/alpha version of the plugin <a href="http://zhandwa.com/downloads/trackchanges/demo/js/jquery.form.track.changes.js">here</a>. I have tested it on Firefox 2/3 and Opera 9.5+ only. So all the IE users let me know if you find any bugs (I am sure there will be ;)).</p>
<p>You can check out a dirty demo <a href="http://zhandwa.com/downloads/trackchanges/demo">here</a>.</p>
<p>Let&#8217;s disect the plugin then, and since this is my first jQuery plugin, you may as well treat this as a small how-to-make-a-jquery-plugin tutorial.</p>
<p><strong>Objective: Track changes made to all the fields/elements which are part of a form. Make sure that when the form is submitted, a list of changed field names is sent to the server.</strong></p>
<p>To begin, let us consider a page with a form in it:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;form1&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;border: 1px solid gray; padding: 20px;&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textf1a&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textf1&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Text1&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textf2a&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textf2&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Text2&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textf3a&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textf3&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Text3&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textf4a&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;textf4&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Text4&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rd1a&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rd&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;radio&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> rd1
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rd2a&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rd&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;radio&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> rd2
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;c1a&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;check1&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;OFF&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;country1a&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;country&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span>&gt;</span>
     <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span>&gt;</span>India<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
     <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span>&gt;</span>USA<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submitButtona&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;buttonSubmita&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Submit&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<p>Now, as we see here the form is pre-populated with some values. These values constitute the &#8220;old values&#8221;. When the form is loaded and if its marked to be tracked, all these field values will be saved into a JavaScript variable. Let us first define the variable which will hold these values:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">    <span style="color: #006600; font-style: italic;">// container which holds the initial values</span>
    <span style="color: #003366; font-weight: bold;">var</span> oldValues <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
        set<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>key<span style="color: #339933;">,</span> val<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> val;
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        get<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span>;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>;</pre></div></div>

<p>This pretty much works like a map. We aren&#8217;t really bothered about maintaining unique keys, etc as we should really never have a scenario where duplicates get into the list.</p>
<p>Now let us load up the object with the form&#8217;s field values. Additionally, we will bind the fields with the events on which tracking will take place.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">    <span style="color: #006600; font-style: italic;">// here we read the original values and populate the oldValues object</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// start a loop for each element that is matched</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>count<span style="color: #339933;">,</span> obj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// find all input tags</span>
            <span style="color: #006600; font-style: italic;">// check if the input tag is not a radio button or a checkbox</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>$<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[@type='radio']&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp;&amp;amp; <span style="color: #339933;">!</span>$<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[@type='checkbox']&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                oldValues.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #000066;">name</span><span style="color: #339933;">,</span> obj.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #006600; font-style: italic;">// set the radio button value if it is checked</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[@type='radio']&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp;&amp;amp; obj.<span style="color: #660066;">checked</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    oldValues.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #000066;">name</span><span style="color: #339933;">,</span> obj.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span>;
                <span style="color: #009900;">&#125;</span>
                <span style="color: #006600; font-style: italic;">// set the value to true if its a checkbox and is checked</span>
                <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[@type='checkbox']&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp;&amp;amp; obj.<span style="color: #660066;">checked</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    oldValues.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #000066;">name</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>;
                <span style="color: #009900;">&#125;</span>
                <span style="color: #006600; font-style: italic;">// set the value to false if its a checkbox and is unchecked</span>
                <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[@type='checkbox']&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp;&amp;amp; <span style="color: #339933;">!</span>obj.<span style="color: #660066;">checked</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    oldValues.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #000066;">name</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>;
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #006600; font-style: italic;">// bind the events to the element</span>
            $<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">events</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                addToChangesList<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>;
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
        <span style="color: #006600; font-style: italic;">// do the same as above, but for select elements</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;select&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>count<span style="color: #339933;">,</span> obj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">// don't save the value if its the hidden changelist itself</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>obj.<span style="color: #000066;">name</span> <span style="color: #339933;">==</span> cName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">return</span>;
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #006600; font-style: italic;">// if the select element has no value set for an option,</span>
            <span style="color: #006600; font-style: italic;">// set the option text as the value</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">value</span> <span style="color: #339933;">&amp;</span>amp;&amp;amp; obj.<span style="color: #660066;">value</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                oldValues.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #000066;">name</span><span style="color: #339933;">,</span> obj.<span style="color: #660066;">options</span><span style="color: #009900;">&#91;</span>obj.<span style="color: #660066;">selectedIndex</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                oldValues.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #000066;">name</span><span style="color: #339933;">,</span> obj.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #006600; font-style: italic;">// bind the events to the element</span>
            $<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">events</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                addToChangesList<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>;
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Okay, so let us now create the list which will hold the name of the changed fields.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">    <span style="color: #006600; font-style: italic;">// this is the list which is appended at the very bottom of the form</span>
    <span style="color: #003366; font-weight: bold;">var</span> cName <span style="color: #339933;">=</span> options.<span style="color: #660066;">changeListName</span>;
    <span style="color: #003366; font-weight: bold;">var</span> displayProp <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;display: none;&quot;</span>;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">changeListVisible</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        displayProp <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;display: block;&quot;</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #003366; font-weight: bold;">var</span> changesList <span style="color: #339933;">=</span> <span style="color: #3366CC;">'
&lt;select id=&quot;'</span><span style="color: #339933;">+</span> cName <span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; class=&quot;'</span> <span style="color: #339933;">+</span> options.<span style="color: #660066;">changeListClass</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; style=&quot;'</span> <span style="color: #339933;">+</span> displayProp <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; multiple=&quot;multiple&quot; name=&quot;'</span><span style="color: #339933;">+</span> cName <span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;&gt;&lt;/select&gt;
&nbsp;
'</span>;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>changesList<span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Since the list is appended inside the form itself, it is submitted along with it. Now lets tackle the addition and removal of a field name from this list as and when a change takes place or a change is reverted back.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">    <span style="color: #006600; font-style: italic;">// checks if the value has changed and accordingly</span>
    <span style="color: #006600; font-style: italic;">// adds or removes the element name from the list</span>
    <span style="color: #003366; font-weight: bold;">function</span> addToChangesList<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[@type='checkbox']&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp;&amp;amp; obj.<span style="color: #660066;">checked</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>oldValues.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                removeFromChangedValuesList<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>;
            <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                addToChangedValuesList<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>;
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">return</span>;
        <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[@type='checkbox']&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp;&amp;amp; <span style="color: #339933;">!</span>obj.<span style="color: #660066;">checked</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>oldValues.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                removeFromChangedValuesList<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>;
            <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                addToChangedValuesList<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>;
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">return</span>;
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>oldValues.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> obj.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>$<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[@type='radio']&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                addToChangedValuesList<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>;
            <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">checked</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    addToChangedValuesList<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>;
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            removeFromChangedValuesList<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>;</pre></div></div>

<p>I will probably simplify/optimize the code here as and when I get time. Following are the methods to add and remove from the list:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">    <span style="color: #006600; font-style: italic;">// removes an element from the list</span>
    <span style="color: #003366; font-weight: bold;">function</span> removeFromChangedValuesList<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> cvs <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;form&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span> <span style="color: #339933;">+</span> cName<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span>;
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>cvs<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span>;
        <span style="color: #009900;">&#125;</span>
&nbsp;
        len <span style="color: #339933;">=</span> cvs.<span style="color: #660066;">length</span>;
        <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> 0; i <span style="color: #339933;">&amp;</span>lt; len; i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>obj.<span style="color: #000066;">name</span> <span style="color: #339933;">==</span> cvs.<span style="color: #660066;">options</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                cvs.<span style="color: #660066;">options</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span>;
                <span style="color: #000066; font-weight: bold;">return</span>;
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// adds an element to the list</span>
    <span style="color: #003366; font-weight: bold;">function</span> addToChangedValuesList<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> cvs <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span> <span style="color: #339933;">+</span> cName<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span>;
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>cvs<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span>;
        <span style="color: #009900;">&#125;</span>
&nbsp;
        len <span style="color: #339933;">=</span> cvs.<span style="color: #660066;">length</span>;
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>len <span style="color: #339933;">==</span> 0<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            cvs.<span style="color: #660066;">options</span><span style="color: #009900;">&#91;</span>len<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Option<span style="color: #009900;">&#40;</span>obj.<span style="color: #000066;">name</span><span style="color: #339933;">,</span> obj.<span style="color: #000066;">name</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>;
            cvs.<span style="color: #660066;">options</span><span style="color: #009900;">&#91;</span>len<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">selected</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span>;
        <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> 0; i <span style="color: #339933;">&amp;</span>lt; len; i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>obj.<span style="color: #000066;">name</span> <span style="color: #339933;">==</span> cvs.<span style="color: #660066;">options</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">return</span>;
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            cvs.<span style="color: #660066;">options</span><span style="color: #009900;">&#91;</span>len<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Option<span style="color: #009900;">&#40;</span>obj.<span style="color: #000066;">name</span><span style="color: #339933;">,</span> obj.<span style="color: #000066;">name</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>;
            cvs.<span style="color: #660066;">options</span><span style="color: #009900;">&#91;</span>len<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">selected</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span>;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>I return the old values object in the response, just in case if the user wants to do some manual checks.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">    <span style="color: #006600; font-style: italic;">// we return the old values object, such that the user has access to the initial values</span>
    <span style="color: #006600; font-style: italic;">// the change list is available in the form as an element</span>
    <span style="color: #006600; font-style: italic;">// the new values are obviously with the user in the form</span>
    <span style="color: #000066; font-weight: bold;">return</span> oldValues;</pre></div></div>

<p>As you might have guessed, since we are sending a select list with multiple values, and each value is selected by default; on the server side all we need to do is retrieve the change list is:</p>
<p>The following code snippet is in Java/JSP.</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;">    <span style="color: #339933;">&amp;</span>lt;%
	<span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> cList <span style="color: #339933;">=</span> request.<span style="color: #006633;">getParameterValues</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;form1TrackList&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> 0; i <span style="color: #339933;">&amp;</span>lt; cList.<span style="color: #006633;">length</span>; i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		out.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>cList<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
    <span style="color: #339933;">%&amp;</span>gt;</pre></div></div>

<p>I hope this plugin solves some of your problems, it definitely helped me out. Let me know of bugs, improvements, etc. <img src='http://code.zhandwa.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div id="st2008071517" class="st-taf"><script src="http://tellafriend.socialtwist.com:80/wizard/js/shoppr.core.js?id=2008071517"></script><img style="border:0;" src="http://tellafriend.socialtwist.com:80/wizard/getButton.jsp?id=2008071517" onmouseout="hideHoverMap(this)" onmouseover="showHoverMap(this, '2008071517',  'http%3A%2F%2Fcode.zhandwa.com%2F2008%2F07%2F31%2Fjquery-track-changes-in-your-forms%2F', 'jQuery%3A+Track+changes+in+your+forms')" onclick="cw(this, {id:'2008071517',link: 'http%3A%2F%2Fcode.zhandwa.com%2F2008%2F07%2F31%2Fjquery-track-changes-in-your-forms%2F', title: '+jQuery%3A+Track+changes+in+your+forms+' })"/></div>]]></content:encoded>
			<wfw:commentRss>http://code.zhandwa.com/2008/07/31/jquery-track-changes-in-your-forms/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Trying out groovy - reading and writing files - part II</title>
		<link>http://code.zhandwa.com/2008/07/29/trying-out-groovy-reading-and-writing-files-part-ii/</link>
		<comments>http://code.zhandwa.com/2008/07/29/trying-out-groovy-reading-and-writing-files-part-ii/#comments</comments>
		<pubDate>Mon, 28 Jul 2008 21:16:16 +0000</pubDate>
		<dc:creator>zhandwa</dc:creator>
		
		<category><![CDATA[scripts]]></category>

		<category><![CDATA[groovy]]></category>

		<category><![CDATA[LineNumberReader]]></category>

		<guid isPermaLink="false">http://code.zhandwa.com/?p=19</guid>
		<description><![CDATA[In my previous post, I had successfully started off with Groovy by simply reading a file, manipulating the content and writing it to another file. Following on the requirements, I now had a new objective.
Objective: Read the country code from one file, the country name from another file, use both the values and put it [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a title="Groovy - I" href="http://code.zhandwa.com/2008/07/27/trying-out-groovy-reading-and-writing-files/" target="_blank">previous post</a>, I had successfully started off with <a title="Groovy Codehaus" href="http://groovy.codehaus.org/" target="_blank">Groovy</a> by simply reading a file, manipulating the content and writing it to another file. Following on the requirements, I now had a new objective.</p>
<p><strong>Objective: Read the country code from one file, the country name from another file, use both the values and put it in the SQL query. So, what I needed now was something like this:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;">insert into the<span style="color: #339933;">-</span>table values<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the-country-code'</span>, <span style="color: #0000ff;">'some-value'</span>, <span style="color: #0000ff;">'and-more'</span>, <span style="color: #0000ff;">'the-country-name'</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>My Java based approach (or rather the first thing that came to my mind :)) here would be to use the <a title="LineNumberReader API" href="http://java.sun.com/j2se/1.4.2/docs/api/java/io/LineNumberReader.html" target="_blank">LineNumberReader</a> class and get content from the second file depending upon on which line I am in the first file. So, first as suggested by <a title="andhapp.com" href="http://www.andhapp.com/" target="_blank">andhapp</a> I stripped off the extra code which was not needed.</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;">targetFile <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;C:/2.txt&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>targetFile<span style="color: #009900;">&#41;</span> targetFile.<span style="color: #006633;">write</span> <span style="color: #0000ff;">&quot;&quot;</span>
<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;C:/1.txt&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">eachLine</span><span style="color: #009900;">&#123;</span>targetFile.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;insert into the-table values('&quot;</span> <span style="color: #339933;">+</span> it <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;', 'some-value', 'and-more');<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Second, I created a LineNumberReader and fed it the country name file. Since the LineNumberReader automatically increments the line number after a read, this became an incredibly easy operation. Now all I had to do was run the eachLine loop again.</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;">targetFile <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;C:/2.txt&quot;</span><span style="color: #009900;">&#41;</span>;
nl <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">LineNumberReader</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">FileReader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;C:/3.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>targetFile<span style="color: #009900;">&#41;</span> targetFile.<span style="color: #006633;">write</span> <span style="color: #0000ff;">&quot;&quot;</span>;
<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;C:/1.txt&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">eachLine</span> <span style="color: #009900;">&#123;</span>
    line2 <span style="color: #339933;">=</span> nl.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    targetFile.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;insert into the-table values('&quot;</span> <span style="color: #339933;">+</span> it <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;', 'some-value', 'and-more', '&quot;</span> <span style="color: #339933;">+</span> line2 <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;');<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Cool, isn&#8217;t it? <img src='http://code.zhandwa.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> I am sure if I would have done this in pure Java, it would be a lot more lines and the fact that I would have to create a class and all. I will be playing around with <a title="Groovy regex docs" href="http://groovy.codehaus.org/Regular+Expressions" target="_blank">Groovy&#8217;s regex support</a> next, so keep watching this place. <img src='http://code.zhandwa.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div id="st2008071517" class="st-taf"><script src="http://tellafriend.socialtwist.com:80/wizard/js/shoppr.core.js?id=2008071517"></script><img style="border:0;" src="http://tellafriend.socialtwist.com:80/wizard/getButton.jsp?id=2008071517" onmouseout="hideHoverMap(this)" onmouseover="showHoverMap(this, '2008071517',  'http%3A%2F%2Fcode.zhandwa.com%2F2008%2F07%2F29%2Ftrying-out-groovy-reading-and-writing-files-part-ii%2F', 'Trying+out+groovy+-+reading+and+writing+files+-+part+II')" onclick="cw(this, {id:'2008071517',link: 'http%3A%2F%2Fcode.zhandwa.com%2F2008%2F07%2F29%2Ftrying-out-groovy-reading-and-writing-files-part-ii%2F', title: '+Trying+out+groovy+-+reading+and+writing+files+-+part+II+' })"/></div>]]></content:encoded>
			<wfw:commentRss>http://code.zhandwa.com/2008/07/29/trying-out-groovy-reading-and-writing-files-part-ii/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Code comments - do we need them?</title>
		<link>http://code.zhandwa.com/2008/07/27/code-comments-do-we-need-them/</link>
		<comments>http://code.zhandwa.com/2008/07/27/code-comments-do-we-need-them/#comments</comments>
		<pubDate>Sun, 27 Jul 2008 08:25:55 +0000</pubDate>
		<dc:creator>zhandwa</dc:creator>
		
		<category><![CDATA[code-ramblings]]></category>

		<category><![CDATA[coding practices]]></category>

		<category><![CDATA[comments]]></category>

		<category><![CDATA[ramblings]]></category>

		<guid isPermaLink="false">http://code.zhandwa.com/?p=14</guid>
		<description><![CDATA[Recently Jeff Attwood and a few others blogged about how we probably don&#8217;t need a lot of comments in our code, provided we write good, readable and self explanatory code. Jeff&#8217;s blog post definitely proves a point and the example he has put forward to prove his point sounds correct as well.
I came across Dan&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Recently <a href="http://www.codinghorror.com/blog/archives/001150.html">Jeff Attwood</a> and a few <a title="steve yegge" href="http://steve-yegge.blogspot.com/2008/02/portrait-of-n00b.html" target="_blank">others</a> blogged about how we probably don&#8217;t need a lot of comments in our code, provided we write good, readable and self explanatory code. Jeff&#8217;s blog post definitely proves a point and the example he has put forward to prove his point sounds correct as well.</p>
<p>I came across <a title="Dan's Blog" href="http://blog.uncommons.org/2008/07/25/no-your-code-is-not-so-great-that-it-doesnt-need-comments/" target="_blank">Dan&#8217;s</a> blog entry later the same day and realized that he too makes a good point. Both sound absolutely correct to me - and equally incorrect as well.</p>
<p>We all assume that we live in a day and age of rapid development and fast internet access everywhere. That, in my opinion is dangerous to assume. Let&#8217;s look at the example Jeff posted at his blog:</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;">r <span style="color: #339933;">=</span> n <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span>;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span> abs<span style="color: #009900;">&#40;</span> r <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>n<span style="color: #339933;">/</span>r<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> t <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  r <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.5</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span> r <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>n<span style="color: #339933;">/</span>r<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;r = &quot;</span> <span style="color: #339933;">+</span> r <span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>This was transformed into a better solution by Jeff into:</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">double</span> SquareRootApproximation<span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  r <span style="color: #339933;">=</span> n <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span>;
  <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span> abs<span style="color: #009900;">&#40;</span> r <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>n<span style="color: #339933;">/</span>r<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> t <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    r <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.5</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span> r <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>n<span style="color: #339933;">/</span>r<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">return</span> r;
<span style="color: #009900;">&#125;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;r = &quot;</span> <span style="color: #339933;">+</span> SquareRootApproximation<span style="color: #009900;">&#40;</span>r<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Dan on his post converted this to:</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Approximate the square root of n, to within the specified tolerance,
 * using the Newton-Raphson method.
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">double</span> approximateSquareRoot<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span> n, <span style="color: #000066; font-weight: bold;">double</span> tolerance<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">double</span> root <span style="color: #339933;">=</span> n <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span>;
    <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>abs<span style="color: #009900;">&#40;</span>root <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>n <span style="color: #339933;">/</span> root<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> tolerance<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        root <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.5</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>root <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>n <span style="color: #339933;">/</span> root<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">return</span> root;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>According to me, Dan&#8217;s version is the better one. As it at least gives you an idea of what could possibly be going on here.</p>
<p>I have a different story to tell here. I was called upon to fix a bug (since I was the only Java guy around) that was causing a lot of pain for some people. The code was pretty to look at. <img src='http://code.zhandwa.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> Most methods had comments and variable names were understandable as well. But then I reached a point where I was totally lost.</p>
<p>There was this method, which was doing something. It was following some algorithm, the code even mentioned the algorithm&#8217;s name (which I don&#8217;t remember right now :)). It was hardly 10 lines of code, but probably the most archaic, wierd piece of code I have ever seen. Now, as Dan said, if you know which algorithm is being used, then just Google it and understand the code.</p>
<p>Unfortunately, that was not possible. Yes, you heard it right. No Google. As a matter for fact, no active net connection as well. The code was on a server machine, placed in a high security - no code goes in or out - kind of environment. There was no way I could have jotted down some information about the method and later check it out over the net for references and solutions. Nothing. nada.</p>
<p>So I was there, trying my best to figure out what&#8217;s happening. Just knowing &#8220;Newton-Raphson&#8221; doesn&#8217;t help. In cases like these, &#8220;better, understandable&#8221; code doesn&#8217;t help as well. The only thing that I wanted to know was what the hell was going on in that method! And I had absolutely no help, whatsoever.</p>
<p>Finally, I had to sit down, write the whole algorithm down mathematically on paper, understand its objective in life, consult with the business behind the application and figure out what was wrong in the code.</p>
<p>All I wanted was 2-3 lines of &#8220;code commenting&#8221;.</p>
<p>I see people commenting almost every line that they write. Some people suggest the 3:1 rule, where you write 3 lines of comment for every line of code you write. All used to sound totally ridiculous to me - till that day. That day, I just wanted some English in between all the code. <img src='http://code.zhandwa.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div id="st2008071517" class="st-taf"><script src="http://tellafriend.socialtwist.com:80/wizard/js/shoppr.core.js?id=2008071517"></script><img style="border:0;" src="http://tellafriend.socialtwist.com:80/wizard/getButton.jsp?id=2008071517" onmouseout="hideHoverMap(this)" onmouseover="showHoverMap(this, '2008071517',  'http%3A%2F%2Fcode.zhandwa.com%2F2008%2F07%2F27%2Fcode-comments-do-we-need-them%2F', 'Code+comments+-+do+we+need+them%3F')" onclick="cw(this, {id:'2008071517',link: 'http%3A%2F%2Fcode.zhandwa.com%2F2008%2F07%2F27%2Fcode-comments-do-we-need-them%2F', title: '+Code+comments+-+do+we+need+them%3F+' })"/></div>]]></content:encoded>
			<wfw:commentRss>http://code.zhandwa.com/2008/07/27/code-comments-do-we-need-them/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
