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

<channel>
	<title>NewInstance &#187; JavaScript</title>
	<atom:link href="http://en.newinstance.it/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://en.newinstance.it</link>
	<description>Welcome to the official blog of Luigi R. Viggiano. Beware of imitations.</description>
	<lastBuildDate>Mon, 09 Jan 2012 20:29:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How GWT is useful in place of  Javascript and CSS?</title>
		<link>http://en.newinstance.it/2010/04/09/how-gwt-is-useful-in-place-of-javascript-and-css/</link>
		<comments>http://en.newinstance.it/2010/04/09/how-gwt-is-useful-in-place-of-javascript-and-css/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 10:54:24 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[GWT]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Opinion]]></category>

		<guid isPermaLink="false">http://en.newinstance.it/2010/04/09/how-gwt-is-useful-in-place-of-javascript-and-css/</guid>
		<description><![CDATA[Currently I am using GWT for a new project and I am really enthusiast of the results. I think it could be a nice article for this blog to explain some GWT ideas and how it is changing the way modern web application are being written. With GWT you use a subset of Java Core [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic -->Currently I am using GWT for a new project and I am really enthusiast of the results. I think it could be a nice article for this blog to explain some GWT ideas and how it is changing the way modern web application are being written.</p>
<p>With GWT you use a subset of Java Core libraries and GWT apis to implement your web application. The web application later can be translated in a 100% JavaScript application that can invoke server side services also written in Java: plain servlets using GWT toolset that make easier to serialize and transfer object between the Java Server and JavaScript application you obtained from GWT. And, as everything is written in Java on the first step, it becomes very easy to keep structures compatible and aligned between client and server.</p>
<p>With GWT you can layout your html pages almost as usual, and inject your GWT components in DIVs defined in the hosting html page.<br />
Modeling the layout of forms and buttons and advanced controls is like writing Swing applications. But the interaction with the server must always be asyncronous (the first "A" of ajax).</p>
<p>GWT is cross browser (version 1.7 covers internet explorer 8 fanciness), has the best support for iternationalization I've ever seen in a web framework, can handle JSON, XML, SOAP or a native and simple google solution as protocol for calling remote services (GWT-RPC).</p>
<p>During the development you only debug Java code, in an "hosted mode" browser. You can put breakpoint on the code that later will be translated in JavaScript, and it really works fine.</p>
<p>If you have your javascript, you can write your Java "wrapper" and have that running as a native GWT library.</p>
<p>GWT also includes a good "back button" handling, javascript code obfuscation/optimization, and whatever you may dream to have from a framework.</p>
<p>but... it's not that simple! you will need some time to master all its feature and understand the internals.</p>
<p>Also a weakness is that at the moment you may have many troubles to get it working with maven, as GWT comes with a "standard" project layout relying on ant script. GWT provides a command line tool to jump start your project and have everything you need to import it in eclipse (maybe also intellij and netbeans).</p>
<p>GWT does not replace CSS. You still use CSS to modify how your GWT widgets will be rendered. Also there are some css predefined to have theming.</p>
<p>This is the <a href="http://code.google.com/intl/it/webtoolkit/gettingstarted.html">quickstart</a>.</p>
<p>This is the <a href="http://gwt.google.com/samples/Showcase/Showcase.html">showcase</a> to see some of the basic widget you can use and the java source code.</p>
<p>It may be surprising but the compilation from Java to JavaScript really works great! Recently a Java port of Quake (Jake) has been cross compiled into Javascript and HTML5 using GWT: <a href="http://code.google.com/p/quake2-gwt-port/">quake2-gwt-port</a>. </p>
<p>Source: <a href="http://www.linkedin.com/answers?viewQuestion=&#038;questionID=532985&#038;askerID=16203097&#038;goback=.mml_inbox_none_DATE_1.mid_1952559178">How GWT is useful in place of  Javascript and CSS?</a>
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2006/09/27/client-side-html-table-pagination-with-javascript/" rel="bookmark" class="crp_title">Client-side HTML table pagination with JavaScript</a></li>
<li><a href="http://en.newinstance.it/2005/09/21/better-html-buttons-with-images/" rel="bookmark" class="crp_title">Better HTML Buttons&#8230; with images</a></li>
<li><a href="http://en.newinstance.it/2005/06/11/progress-bar-while-computing/" rel="bookmark" class="crp_title">Progress bar while computing&#8230;</a></li>
<li><a href="http://en.newinstance.it/2011/06/01/checking-configuration-files-inside-jars/" rel="bookmark" class="crp_title">Checking configuration files inside jars</a></li>
<li><a href="http://en.newinstance.it/2006/12/02/give-color-to-your-code/" rel="bookmark" class="crp_title">Give color to your code!</a></li>
</ul>
</div>
<div class="shr-publisher-409"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2010%2F04%2F09%2Fhow-gwt-is-useful-in-place-of-javascript-and-css%2F' data-shr_title='How+GWT+is+useful+in+place+of++Javascript+and+CSS%3F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2010%2F04%2F09%2Fhow-gwt-is-useful-in-place-of-javascript-and-css%2F' data-shr_title='How+GWT+is+useful+in+place+of++Javascript+and+CSS%3F'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2010%2F04%2F09%2Fhow-gwt-is-useful-in-place-of-javascript-and-css%2F' data-shr_title='How+GWT+is+useful+in+place+of++Javascript+and+CSS%3F'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2010/04/09/how-gwt-is-useful-in-place-of-javascript-and-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DHTML Lemmings</title>
		<link>http://en.newinstance.it/2007/08/29/dhtml-lemmings/</link>
		<comments>http://en.newinstance.it/2007/08/29/dhtml-lemmings/#comments</comments>
		<pubDate>Wed, 29 Aug 2007 21:57:41 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://it.newinstance.it/2007/08/29/dhtml-lemmings/</guid>
		<description><![CDATA[What nice things can be done with Javascript! I&#8217;m astonished. I loved that game, now we have Lemmings in DHTML (DOM, HTML, CSS and Javascript of course). Running in any modern browser. Very cool. I&#8217;ll go looking for a port for pocket pc and palm. Related Posts: Cool tool: Windows Live Writer How to create [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><a href="http://www.elizium.nu/scripts/lemmings/" target="_blank"><img src="http://farm2.static.flickr.com/1200/1270383156_ac9f22c62a_o.png" width="500" height="343" alt="dhtml-lemmings" /></a></p>
<p>What nice things can be done with Javascript! I&#8217;m astonished.<br />
I loved that game, now we have <a href="http://www.elizium.nu/scripts/lemmings/" target="_blank">Lemmings in DHTML</a> (DOM, HTML, CSS and Javascript of course). Running in any modern browser.</p>
<p>Very cool. I&#8217;ll go looking for a port for pocket pc and palm.
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2006/08/16/cool-tool-windows-live-writer/" rel="bookmark" class="crp_title">Cool tool: Windows Live Writer</a></li>
<li><a href="http://en.newinstance.it/2011/02/27/how-to-create-a-statically-linked-version-of-git-binaries/" rel="bookmark" class="crp_title">How to create a statically linked version of git binaries</a></li>
<li><a href="http://en.newinstance.it/2010/04/09/how-gwt-is-useful-in-place-of-javascript-and-css/" rel="bookmark" class="crp_title">How GWT is useful in place of  Javascript and CSS?</a></li>
<li><a href="http://en.newinstance.it/2005/10/31/another-one-bites-the-dust/" rel="bookmark" class="crp_title">Another One Bites The Dust!</a></li>
<li><a href="http://en.newinstance.it/2005/06/11/progress-bar-while-computing/" rel="bookmark" class="crp_title">Progress bar while computing&#8230;</a></li>
</ul>
</div>
<div class="shr-publisher-262"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2007%2F08%2F29%2Fdhtml-lemmings%2F' data-shr_title='DHTML+Lemmings'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2007%2F08%2F29%2Fdhtml-lemmings%2F' data-shr_title='DHTML+Lemmings'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2007%2F08%2F29%2Fdhtml-lemmings%2F' data-shr_title='DHTML+Lemmings'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2007/08/29/dhtml-lemmings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Email URL Encoder Tool</title>
		<link>http://en.newinstance.it/2006/10/31/email-url-encoder-tool/</link>
		<comments>http://en.newinstance.it/2006/10/31/email-url-encoder-tool/#comments</comments>
		<pubDate>Tue, 31 Oct 2006 14:30:08 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Lifehacks]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://it.newinstance.it/2006/10/31/email-url-encoder-tool/</guid>
		<description><![CDATA[I've just written this little tool to encode email templates into mailto URLs. It's based on URL Decoder/Encoder by Eric Meyer. Hope it could be useful to someone. The "to" field is mandatory. You can specify multiple values separated by comma. For more info on mailto URLs, see rfc2368. To download this script just grab [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>I've just written this little tool to encode email templates into mailto URLs.
It's based on <a href="http://meyerweb.com/eric/tools/dencoder/">URL Decoder/Encoder</a> by <a href="http://meyerweb.com">Eric Meyer</a>.<br/>
Hope it could be useful to someone.</p>
<p>The "to" field is mandatory. You can specify multiple values separated by comma.
For more info on mailto URLs, see <a href="http://www.ietf.org/rfc/rfc2368.txt">rfc2368</a>.<br/>
To download this script just grab it from the source of this page.
</p>
<p>Mailto URLs do not support extended (8bit) chars so, for example, accented chars won't work. If you have a fix leave a comment.</p>
<br/>

<style>
	<!--
	div#mailenc h2 {
	  font-family: Arial, sans-serif; 
	  line-height: 0.85em; 
	  border-bottom: 2px solid;
	  margin-bottom: 0.33em; 
	  padding-bottom: 0;
	}

	div#mailenc label, div#mailenc input, div#mailenc textarea {
		display: block;
		width: 300px;
		float: left;
		margin-left: 5px;
		margin-right: 5px;
		margin-bottom: 10px;
	}
	div#mailenc input, div#mailenc textarea {
		background: #EEF;	
	}
	
	div#mailenc label {
		width: 80px;
		font-weight: bold;
		text-align: right;
	}
	div#mailenc label.mandatory {
		color: red;
	}

	div#mailenc fieldset {
		margin-top:10px;
	}
			
	div#mailenc div#buttons {
		margin-top:0px;		
		margin-bottom:20px; 
		text-align:center;
	}

	div#mailenc div#buttons button {
		margin-left: 5px;		
		width: 100px;
	}
	
	div#mailenc br {
		clear: left;
	}   

	div#mailenc {
		width: 480px;		
	}

	div#mailenc #footer {margin-top: 10px; border-top: 1px solid #000; color: #999; font: italic 90% sans-serif; text-align: justify; }
	div#mailenc #footer p {margin: 0 0 1em 0;}
	div#mailenc #footer img {float: right; margin: 0 0 0.5em 2em;}	
									 
	-->
</style>

<script type="text/javascript">
function encode() {
    var label = document.getElementById('label');
	var to = document.getElementById('to');
	var cc = document.getElementById('cc');
	var bcc = document.getElementById('bcc');
	var subj = document.getElementById('subj');
	var body = document.getElementById('body');
	var link = document.getElementById('link');		
	var html = document.getElementById('html');

	if (to.value == '') {
	    alert('Please specify an email address into the \"To\" field. ');
	    return;
	}
	 	 
	html.value = 'mailto:' + escape(to.value);
	
	var separator = '?';
	
	if (cc.value != '') {
	    html.value += separator + 'cc=' + escape(cc.value);
	    separator = '&#038;';
	}

	if (bcc.value != '') {
	    html.value += separator + 'bcc=' + escape(bcc.value);
	    separator = '&#038;';
	}
	
	if (subj.value != '') {
	    html.value += separator + 'subject=' + escape(subj.value);
	    separator = '&#038;';
	}

	if (body.value != '') {
	    html.value += separator + 'body=' + escape(body.value);
	}	
	
	if (label.value == '') {
	    label.value = to.value;
	}
	
	html.value = '<a href=\"' + html.value + '\">\n' + label.value + '\n</a>'
	link.innerHTML = html.value;
}
</script>

<div id="mailenc">
	<form onsubmit="return false;">
		<h2>Email URL Encoder</h2>
		
		<fieldset>		
			<legend>Email</legend>

			<label for="label">Label:</label> 
			<input type="text" id="label"/><br/>
			
			<label for="to" class="mandatory">To:</label> 
			<input type="text" id="to"/><br/>
	
			<label for="cc">Cc:</label> 
			<input type="text" id="cc"/><br/>
	
			<label for="bcc">Bcc:</label> 
			<input type="text" id="bcc"/><br/>
			
			<label for="subj">Subject:</label> 
			<input type="text" id="subj"/><br/>
			
			<label for="body">Body:</label>
			<textarea rows="10" id="body"></textarea><br/>
	
			<div id="buttons">
				<button onclick="encode()">Encode</button>
				<button onclick="reset()">Reset</button>
			</div>
		</fieldset>		
		<fieldset>		
			<legend>Output</legend>
			<label for="html">Generated Html:</label>
			<textarea rows="10" id="html" onclick="this.select()"></textarea><br/>
			
			<label for="link">Link:</label>
			<span id="link">write your email and press &quot;Encode&quot; button.</span>
		</fieldset>
	</form>

	<div id="footer">
		<img alt="Creative Commons License" border="0" src="http://creativecommons.org/images/public/somerights.gif" />
		<p><br/>The Email URL Encoder is based on <a href="http://meyerweb.com/eric/tools/dencoder/">URL Decoder/Encoder</a> by <a href="http://meyerweb.com">Eric Meyer</a> and is licensed under a Creative Commons <a href="http://creativecommons.org/licenses/by-sa/2.0/" rel="license">Attribution-ShareAlike 2.0</a> License.</p>
		<p>This tool is provided without warranty, guarantee, or much in the way of explanation.  Note that use of this tool may or may not crash your browser, lock up your machine, erase your hard drive, or e-mail those naughty pictures you hid in the Utilities folder to your mother.  Don't blame me if anything bad happens to you, because it's actually the aliens' fault.  The code expressed herein is solely that of the author, and he's none too swift with the JavaScript, if you know what we mean, so it's likely to cause giggle fits in anyone who knows what they're doing.  Not a flying toy. <br/>Thank you for playing.  Insert coin to continue.</p>
	</div>
</div>
<div id="crp_related"><h4>Related Posts:</h4><ul><li><a href="http://en.newinstance.it/2005/09/21/better-html-buttons-with-images/" rel="bookmark" class="crp_title">Better HTML Buttons&#8230; with images</a></li><li><a href="http://en.newinstance.it/2005/06/13/anti-spam-email-hiding-techniques/" rel="bookmark" class="crp_title">Anti spam email hiding techniques</a></li><li><a href="http://en.newinstance.it/2006/09/27/client-side-html-table-pagination-with-javascript/" rel="bookmark" class="crp_title">Client-side HTML table pagination with JavaScript</a></li><li><a href="http://en.newinstance.it/2005/06/17/adding-hidden-fields-to-a-form/" rel="bookmark" class="crp_title">Adding hidden fields to a Form</a></li><li><a href="http://en.newinstance.it/2005/07/28/bug-parade/" rel="bookmark" class="crp_title">Bug Parade</a></li></ul></div><div class="shr-publisher-201"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2006%2F10%2F31%2Femail-url-encoder-tool%2F' data-shr_title='Email+URL+Encoder+Tool'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2006%2F10%2F31%2Femail-url-encoder-tool%2F' data-shr_title='Email+URL+Encoder+Tool'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2006%2F10%2F31%2Femail-url-encoder-tool%2F' data-shr_title='Email+URL+Encoder+Tool'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2006/10/31/email-url-encoder-tool/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Client-side HTML table pagination with JavaScript</title>
		<link>http://en.newinstance.it/2006/09/27/client-side-html-table-pagination-with-javascript/</link>
		<comments>http://en.newinstance.it/2006/09/27/client-side-html-table-pagination-with-javascript/#comments</comments>
		<pubDate>Wed, 27 Sep 2006 16:08:11 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://it.newinstance.it/2006/09/27/client-side-html-table-pagination-with-javascript/</guid>
		<description><![CDATA[Most of the times, you don't need to paginate on the client side: if you have an enough small set of records to be displayed, I would suggest you to choose a scrollable &#60;div/&#62;. Server-side web pagination is really needed when you have to display hundreds of records. You may fetch results from the DB [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Most of the times, you don't need to paginate on the client side: if you have an enough small set of records to be displayed, I would suggest you to choose a scrollable &lt;div/&gt;. </p>

<p>Server-side web pagination is really needed when you have to display hundreds of records. You may fetch results from the DB using an offset and loading a single page for each HTTP request. <br />
If your resultset is small it's possible to load it fully. Sometime I saw code loading the full resultset in session; and on each page-switch the browser refreshes displaying a different subset/page. There are many disadvantages of a server-side pagination like this:
<ul>
<li>You have to use the HTTP Session (and remember to clean up when it's nomore needed).</li>
<li>You have to reload the page on every page switch.</li>
<li>You cannot go forward and backward to check previous data without loosing the view on current resultset.</li>
<li>You have to write code for the server side actions handling all the page-switch work.</li>
</ul>
</p>

<p>As I said before, everything would be solved using a table inside scrollable div but, in my current web application "GUI designers" like to persecute the users having them clicking and clicking even for few records. As in my case, I have an "editable table" (an html form) that's also paginated, in wich validation of each record depends on other records...<br />
At least I wanted to avoid reloading the page on every page switch, and also avoid using HTTP Session when not strictly necessary. So I end up writing a JavaScript paginator object that handles the job of paginating any html table rendering also a simple pagination bar.</p>
<p>Here's a live sample: </p>

<div style="border: 1px solid; padding: 5px;">
<style type="text/css">    
    .pg-normal {
        color: black;
        font-weight: normal;
        text-decoration: none;    
        cursor: pointer;    
    }
    .pg-selected {
        color: black;
        font-weight: bold;        
        text-decoration: underline;
        cursor: pointer;
    }
</style>


<script type="text/javascript" src="http://it.newinstance.it/wp-content/uploads/2006/09/paging.js"></script>

<form action="" method="get" enctype="application/x-www-form-urlencoded">
<table id="results">
    <tr>
        <th>#</th>
        <th>field</th>
    </tr>
    <tr>
        <td>1</td>
        <td><input type="text" name="field-name" value="rec1"></td>
    </tr>
    <tr>
        <td>2</td>
        <td><input type="text" name="field-name" value="rec2"></td>
    </tr>
    <tr>
        <td>3</td>
        <td><input type="text" name="field-name" value="rec3"></td>
    </tr>
    <tr>
        <td>4</td>
        <td><input type="text" name="field-name" value="rec4"></td>
    </tr>
    <tr>
        <td>5</td>
        <td><input type="text" name="field-name" value="rec5"></td>
    </tr>
    <tr>
        <td>6</td>
        <td><input type="text" name="field-name" value="rec6"></td>
    </tr>
    <tr>
        <td>7</td>
        <td><input type="text" name="field-name" value="rec7"></td>
    </tr>
    <tr>
        <td>8</td>
        <td><input type="text" name="field-name" value="rec8"></td>
    </tr>
    <tr>
        <td>9</td>
        <td><input type="text" name="field-name" value="rec9"></td>
    </tr>
    <tr>
        <td>10</td>
        <td><input type="text" name="field-name" value="rec10"></td>
    </tr>
</table>
<div id="pageNavPosition"></div>
<div><input type="submit" onclick="alert('Hey, this is just a sample!'); return false;" />&nbsp;<input type="reset" /></div>
</form>

<script type="text/javascript"><!--
    var pager = new Pager('results', 3); 
    pager.init(); 
    pager.showPageNav('pager', 'pageNavPosition'); 
    pager.showPage(1);
//--></script>

</div>

<p>To use my javascript you need to:
<ol>
<li>include the javascript using &lt;script src="pager.js"&gt; in your page header;</li>
<li>include a small css to skin the page navigation-bar (i.e. for emphasizing the selected page using bold and underline style);</li>
<li>define an ID on the table you want to scroll. i.e. &lt;table id="results"&gt; ;</li>
<li>place an empty &lt;div/&gt; in the place you want to display the navigation bar. i.e. &lt;div id="pageNavPosition"&gt; ; </li>
<li>include an initialization script at the bottom of your page like this:<pre>
&lt;script type="text/javascript"&gt;&lt;!--
    var <span style="color:red">pager</span> = new Pager('results', 3); 
    pager.init(); 
    pager.showPageNav('<span style="color:red">pager</span>', 'pageNavPosition'); 
    pager.showPage(1);
//--&gt;&lt;/script&gt;</pre>
Where 'results' is the id of the table (see step #3), 3 is the number of records per page, 'pager' is the name of the variable (in red... that's ugly I agree...), and pageNavPosition is the ID of the DIV inside of which the pagination bar will be placed. The showPage(1) indicates that, when loading the page, the 1st one should be displayed.
</li>
</ol>
That's all. If you want to download a demo (html+javascript files), you can click here: <a id="p123" href="http://it.newinstance.it/wp-content/uploads/2006/09/paging-demo.zip">JavaScript Table Paginator Demo</a>.
</p>

<p>
If you have a huge table, maybe it will be displayed fully before the javascript at the bottom will be executed. To avoid this, you can set the table as hidden by default using css style, and make it visibile using JavaScript after the pager.showPage() call.
</p><div id="crp_related"><h4>Related Posts:</h4><ul><li><a href="http://en.newinstance.it/2005/06/11/progress-bar-while-computing/" rel="bookmark" class="crp_title">Progress bar while computing&#8230;</a></li><li><a href="http://en.newinstance.it/2005/06/17/adding-hidden-fields-to-a-form/" rel="bookmark" class="crp_title">Adding hidden fields to a Form</a></li><li><a href="http://en.newinstance.it/2006/10/31/email-url-encoder-tool/" rel="bookmark" class="crp_title">Email URL Encoder Tool</a></li><li><a href="http://en.newinstance.it/2005/06/13/anti-spam-email-hiding-techniques/" rel="bookmark" class="crp_title">Anti spam email hiding techniques</a></li><li><a href="http://en.newinstance.it/2005/09/21/better-html-buttons-with-images/" rel="bookmark" class="crp_title">Better HTML Buttons&#8230; with images</a></li></ul></div><div class="shr-publisher-117"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2006%2F09%2F27%2Fclient-side-html-table-pagination-with-javascript%2F' data-shr_title='Client-side+HTML+table+pagination+with+JavaScript'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2006%2F09%2F27%2Fclient-side-html-table-pagination-with-javascript%2F' data-shr_title='Client-side+HTML+table+pagination+with+JavaScript'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2006%2F09%2F27%2Fclient-side-html-table-pagination-with-javascript%2F' data-shr_title='Client-side+HTML+table+pagination+with+JavaScript'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2006/09/27/client-side-html-table-pagination-with-javascript/feed/</wfw:commentRss>
		<slash:comments>109</slash:comments>
		</item>
		<item>
		<title>Better HTML Buttons&#8230; with images</title>
		<link>http://en.newinstance.it/2005/09/21/better-html-buttons-with-images/</link>
		<comments>http://en.newinstance.it/2005/09/21/better-html-buttons-with-images/#comments</comments>
		<pubDate>Tue, 20 Sep 2005 23:12:49 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://it.newinstance.it/2005/09/21/better-html-buttons-with-images/</guid>
		<description><![CDATA[I never understood why HTML spec, still links the action of a form to the form itself: in a form you may need more possibility (edit, delete, insert, etc...) and you'll have many buttons then, so I think that html should link the action to the button, like in any intelligent gui language.So it would [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>I never understood why HTML spec, still links the action of a form to the form itself: in a form you may need more possibility (edit, delete, insert, etc...) and you'll have many buttons then, so I think that html should link the action to the button, like in any intelligent gui language.<br />So it would be more useful a tag like:<br/> <tt>&lt;input type="submit" action="servleturl"/&gt;</tt>
<p>In current project we used Tag Files, a feature available in JSP 2.0 specification: you can write tags using JSP, and this is very good if your tags must produce some template code.  <p>One of our Tag File uses a syntax <em>like</em> the following:</p>
<p>
<pre>&lt;my:button action="update.jspa" &gt;
    &lt;ww:text name="'application.update.button'" /&gt;
&lt;/my:button&gt;
</pre>
</p>
<p>the <tt>action</tt> attribute is mandatory, but if you need you can define your tag with more optional attributes, for example to add javascript execution, or to ask "are you sure?" alert, etc...<br />The action identifies the application controller (i.e. a servlet) that will be executed when button is clicked. <br />The label of the button is defined by the body content of the <tt>my:button</tt> tag. In this case the <tt>"&lt;ww:text name="'application.modify.button'" /&gt;"</tt> is resolved by a webwork <tt>&lt;ww:text /&gt;</tt> tag that provides internationalization(i.e. will display: "update" string for Americans, and "aggiorna" for Italians). 
<p>With a simple javavascript I am able to obtain enclosing form (owner of the button), changing the action of the form tag on the fly, then submit the form: in this way, buttons are associated with action. <br />The <tt>&lt;form /&gt;</tt> tag will specify the <tt>action</tt> attribute as an empty string (as it is mandatory): <tt>&lt;form action=""/&gt;</tt> 
<p>The nice thing of having a body of the tag button, is that you can include something inside it, and you are completely free! (you can insert a table, if you like... hey, stop! don't do that!). 
<p>For example, an icon with corresponding description: </p>
<p>
<pre>&lt;my:button action="http://www.google.com/"&gt;
     &lt;ww:url id="imagesurl" value="'http://it.newinstance.it/wp-content/uploads/2006/10/export.png'" includeParams="'none'" /&gt;
     &lt;img style="border: 0; vertical-align: middle; margin-right: 5px;" src="&lt;ww:property value="#imagesurl"/&gt;"/&gt;
     &lt;ww:text name="'application.export.button'" /&gt;
&lt;/my:button&gt;
</pre>
</p>
<p>And this, executing our custom jsp tag file, will render as:</p>
<p><pre>
&lt;button onclick="form.action='http://www.google.com/'; form.submit(); return false" &gt;
     &lt;img style="border: 0px none; vertical-align: middle; margin-right: 5px;" src="http://it.newinstance.it/wp-content/uploads/2006/10/export.png" /&gt;
     Export
&lt;/button&gt;
</pre>
</p>
<p>The "return false" at the end of the javascript is a compatibility issue, to make it behave the same way in different browsers (without it, for instance, explorer will submit the form twice!).
And this is how it will look like:</p>
<div>
<iframe src="http://it.newinstance.it/wp-content/uploads/2006/10/sample-export-button.html" height="60" width="150" frameborder="0"></iframe>
</div>
<p>I won't show here the source code for the button.tag file: it's really trivial, and ... I would have problems with copyright, but the concept is there, and writing a tag that translate the &lt;my:button/&gt; in the source shown, it's really easy.</p><div id="crp_related"><h4>Related Posts:</h4><ul><li><a href="http://en.newinstance.it/2006/10/31/email-url-encoder-tool/" rel="bookmark" class="crp_title">Email URL Encoder Tool</a></li><li><a href="http://en.newinstance.it/2006/09/27/client-side-html-table-pagination-with-javascript/" rel="bookmark" class="crp_title">Client-side HTML table pagination with JavaScript</a></li><li><a href="http://en.newinstance.it/2005/06/11/smarter-use-of-ie-links-toolbar/" rel="bookmark" class="crp_title">Smarter use of IE links toolbar&#8230;</a></li><li><a href="http://en.newinstance.it/2009/02/03/some-things-i-dont-like-about-my-mac/" rel="bookmark" class="crp_title">Some things I don&#8217;t like about my Mac</a></li><li><a href="http://en.newinstance.it/2005/06/17/adding-hidden-fields-to-a-form/" rel="bookmark" class="crp_title">Adding hidden fields to a Form</a></li></ul></div><div class="shr-publisher-136"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F09%2F21%2Fbetter-html-buttons-with-images%2F' data-shr_title='Better+HTML+Buttons...+with+images'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F09%2F21%2Fbetter-html-buttons-with-images%2F' data-shr_title='Better+HTML+Buttons...+with+images'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F09%2F21%2Fbetter-html-buttons-with-images%2F' data-shr_title='Better+HTML+Buttons...+with+images'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2005/09/21/better-html-buttons-with-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding hidden fields to a Form</title>
		<link>http://en.newinstance.it/2005/06/17/adding-hidden-fields-to-a-form/</link>
		<comments>http://en.newinstance.it/2005/06/17/adding-hidden-fields-to-a-form/#comments</comments>
		<pubDate>Thu, 16 Jun 2005 22:33:45 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://it.newinstance.it/2005/06/17/adding-hidden-fields-to-a-form/</guid>
		<description><![CDATA[Today, I've had the problem to dynamically add additional informations to html forms. Not being an expert of JavaScript I thought it was very easy. But after trying to code something like this: ... var form = document.forms['myForm']; form.myHiddenField = new Hidden(); form.myHiddenField.value=myValue; ... I discovered that it's not so easy. I also didn't find [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Today, I've had the problem to dynamically add additional informations to html forms. Not being an expert of JavaScript I thought it was very easy. 
But after trying to code something like this:
</p>
<pre>    <span style="color: rgb(128, 128, 48);">.</span><span style="color: rgb(128, 128, 48);">.</span><span style="color: rgb(128, 128, 48);">.</span>
    <span style="color: rgb(128, 0, 0); font-weight: bold;">var</span> form <span style="color: rgb(128, 128, 48);">=</span> document<span style="color: rgb(128, 128, 48);">.</span>forms<span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 0, 230);">'myForm'</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 0, 128);">;</span>
    form<span style="color: rgb(128, 128, 48);">.</span>myHiddenField <span style="color: rgb(128, 128, 48);">=</span> <span style="color: rgb(128, 0, 0); font-weight: bold;">new</span> Hidden<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 0, 128);">;</span>
    form<span style="color: rgb(128, 128, 48);">.</span>myHiddenField<span style="color: rgb(128, 128, 48);">.</span>value<span style="color: rgb(128, 128, 48);">=</span>myValue<span style="color: rgb(128, 0, 128);">;</span>
    <span style="color: rgb(128, 128, 48);">.</span><span style="color: rgb(128, 128, 48);">.</span><span style="color: rgb(128, 128, 48);">.</span>
</pre>

<p>I discovered that it's not so easy. I also didn't find anything on google. I also looked-up on JGuru, but I just find <a href="http://www.jguru.com/faq/view.jsp?EID=448075">this</a>.</p>

<p>
But I didn't find it satisfactory, because I don't want to remember to add divs to my forms. 
Here's my solution (that I added to JGuru)
</p>

<pre>    <span style="color: rgb(128, 128, 48);">.</span><span style="color: rgb(128, 128, 48);">.</span><span style="color: rgb(128, 128, 48);">.</span>
    <span style="color: rgb(128, 0, 0); font-weight: bold;">var</span> form <span style="color: rgb(128, 128, 48);">=</span> document<span style="color: rgb(128, 128, 48);">.</span>forms<span style="color: rgb(128, 128, 48);">[</span><span style="color: rgb(0, 0, 230);">'myForm'</span><span style="color: rgb(128, 128, 48);">]</span><span style="color: rgb(128, 0, 128);">;</span>
    <span style="color: rgb(128, 0, 0); font-weight: bold;">var</span> el <span style="color: rgb(128, 128, 48);">=</span> document<span style="color: rgb(128, 128, 48);">.</span>createElement<span style="color: rgb(128, 128, 48);">(</span><span style="color: rgb(0, 0, 230);">"input"</span><span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 0, 128);">;</span>
    el<span style="color: rgb(128, 128, 48);">.</span>type <span style="color: rgb(128, 128, 48);">=</span> <span style="color: rgb(0, 0, 230);">"hidden"</span><span style="color: rgb(128, 0, 128);">;</span>
    el<span style="color: rgb(128, 128, 48);">.</span>name <span style="color: rgb(128, 128, 48);">=</span> <span style="color: rgb(0, 0, 230);">"myHiddenField"</span><span style="color: rgb(128, 0, 128);">;</span>
    el<span style="color: rgb(128, 128, 48);">.</span>value <span style="color: rgb(128, 128, 48);">=</span> <span style="color: rgb(0, 0, 230);">"myValue"</span><span style="color: rgb(128, 0, 128);">;</span>
    form<span style="color: rgb(128, 128, 48);">.</span>appendChild<span style="color: rgb(128, 128, 48);">(</span>el<span style="color: rgb(128, 128, 48);">)</span><span style="color: rgb(128, 0, 128);">;</span>
    <span style="color: rgb(128, 128, 48);">.</span><span style="color: rgb(128, 128, 48);">.</span><span style="color: rgb(128, 128, 48);">.</span>  
</pre>

<p>I've tested it with IE6, Firefox 1.0.2, Opera 7.54, but it shold work on any browser.</p><div id="crp_related"><h4>Related Posts:</h4><ul><li><a href="http://en.newinstance.it/2005/06/11/infamous-programming-errors-on-curly-braced-blocks/" rel="bookmark" class="crp_title">Infamous programming errors on curly braced {blocks}</a></li><li><a href="http://en.newinstance.it/2005/07/11/webwork-package-configuration-problem/" rel="bookmark" class="crp_title">Webwork Package Configuration Problem</a></li><li><a href="http://en.newinstance.it/2008/10/24/always-on-getter-and-setters/" rel="bookmark" class="crp_title">Always on getter and setters</a></li><li><a href="http://en.newinstance.it/2005/07/11/hibernate-and-database-views/" rel="bookmark" class="crp_title">Hibernate and Database Views</a></li><li><a href="http://en.newinstance.it/2009/03/05/ant-macrodefs/" rel="bookmark" class="crp_title">Ant macrodefs</a></li></ul></div><div class="shr-publisher-165"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F06%2F17%2Fadding-hidden-fields-to-a-form%2F' data-shr_title='Adding+hidden+fields+to+a+Form'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F06%2F17%2Fadding-hidden-fields-to-a-form%2F' data-shr_title='Adding+hidden+fields+to+a+Form'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F06%2F17%2Fadding-hidden-fields-to-a-form%2F' data-shr_title='Adding+hidden+fields+to+a+Form'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2005/06/17/adding-hidden-fields-to-a-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Anti spam email hiding techniques</title>
		<link>http://en.newinstance.it/2005/06/13/anti-spam-email-hiding-techniques/</link>
		<comments>http://en.newinstance.it/2005/06/13/anti-spam-email-hiding-techniques/#comments</comments>
		<pubDate>Mon, 13 Jun 2005 07:33:15 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://it.newinstance.it/2005/06/13/anti-spam-email-hiding-techniques/</guid>
		<description><![CDATA[Writing email addresses in clear in web pages is not a good idea: spam bot browse the web and collect email address to lately send unrequested spam. But, sometime it could be useful to put an email address in a web page, and there could be several possibility: Using an image: a transparent gif with [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Writing email addresses in clear in web pages is not a good idea: spam bot browse the web and collect email address to lately send unrequested spam. But, sometime it could be useful to put an email address in a web page, and there could be several possibility:
</p>
<ol>
<li>Using an image: a transparent gif with the text of the email. Spambot needs to have some Optical Character Recognization to understand your email (complex enough), but a real user browsing your site cannot copy-and-paste your email, nor cannot click on a simple link to send you an email.</li>
<li>Using a form: let the user send you an email whithout knowing your address. The user will know your email address when you respond to its email. This requires your site to have some server-side capability (CGI/PHP/Servlet) to accomplish this job. But spambot scripts can exploit the form to send you emails: this requires additional work for spam guys, but when you realize that spammers has exploited it you can add to the form some additional mechanism (like "see this image and report what you read", or "3+2=?" or easy question like "Which color was it the white horse of Napoleon?")</li>
<li>Scrambling email addresses: you can do some cryptography on email addresses and using javascript the client's browser will be able to decrypt addresses. The spambot will need to be able to execute javascripts to decode your emails. Complex, but I believe that some can do it.</li>
<li>Adding garbage emails in your pages: you can place some (hidden)links on randomly generated pages on your site so that the spambot, following that links will fall in pages generating infinite email addresses and collecting hundreds of thousand email address with the good ones (this means that the spammer guy will have to discard them manually, or discard all the data collected from that point on. You usually will put a 10+ links on the top and on the bottom of your pages linking random generated pages containing random emails.</li>
</ol>

<p>
A sample of html fragment using javascript for scrambling emails (that I am using) could be the following:
</p>


<pre><span style="color: rgb(127, 0, 85);">&lt;</span><span style="color: rgb(127, 0, 85); font-weight: bold;">script language="</span><span style="color: rgb(42, 0, 255);">JavaScript</span><span style="color: rgb(127, 0, 85); font-weight: bold;">"</span><span style="color: rgb(127, 0, 85);">&gt;</span>
<span style="color: rgb(127, 0, 85); font-weight: bold;">function</span> mail(name, domain, ext, params) {
  <span style="color: rgb(127, 0, 85); font-weight: bold;">var</span> addr = name + <span style="color: rgb(42, 0, 255);">"@"</span> + domain + <span style="color: rgb(42, 0, 255);">"."</span> + ext;
  <span style="color: rgb(127, 0, 85); font-weight: bold;">var</span> protocol = <span style="color: rgb(42, 0, 255);">"ma"</span> + <span style="color: rgb(42, 0, 255);">"il"</span> + <span style="color: rgb(42, 0, 255);">"to"</span>;
  <span style="color: rgb(127, 0, 85); font-weight: bold;">var</span> url = protocol + <span style="color: rgb(42, 0, 255);">":"</span> + addr + params;
  <span style="color: rgb(127, 0, 85); font-weight: bold;">var</span> a = <span style="color: rgb(42, 0, 255);">"&lt;a href="</span> + url + <span style="color: rgb(42, 0, 255);">"&gt;"</span>;
  <span style="color: rgb(127, 0, 85); font-weight: bold;">var</span> _a = <span style="color: rgb(42, 0, 255);">"&lt;/a&gt;"</span>;
  document.write(a + addr + _a);
}                            
<span style="color: rgb(127, 0, 85);">&lt;/</span><span style="color: rgb(127, 0, 85); font-weight: bold;">script</span><span style="color: rgb(127, 0, 85);">&gt;</span>

<span style="color: rgb(127, 0, 85);">&lt;</span><span style="color: rgb(127, 0, 85); font-weight: bold;">strong</span><span style="color: rgb(127, 0, 85);">&gt;</span>Write me: <span style="color: rgb(127, 0, 85);">&lt;/</span><span style="color: rgb(127, 0, 85); font-weight: bold;">strong</span><span style="color: rgb(127, 0, 85);">&gt;</span><span style="color: rgb(127, 0, 85);">&lt;</span><span style="color: rgb(127, 0, 85); font-weight: bold;">script language="</span><span style="color: rgb(42, 0, 255);">JavaScript</span><span style="color: rgb(127, 0, 85); font-weight: bold;">"</span><span style="color: rgb(127, 0, 85);">&gt;</span>mail(<span style="color: rgb(42, 0, 255);">"lviggiano"</span>, <span style="color: rgb(42, 0, 255);">"tiscali"</span>, <span style="color: rgb(42, 0, 255);">"it"</span>, <span style="color: rgb(42, 0, 255);">""</span>);<span style="color: rgb(127, 0, 85);">&lt;/</span><span style="color: rgb(127, 0, 85); font-weight: bold;">script</span><span style="color: rgb(127, 0, 85);">&gt;</span>

</pre>


<p>
I aways combine this technique with the garbage email generation. A sample a gargbage email generator written in php (as I had some difficult finding java-enabled hosting for my site) is the following:
</p>

<pre style="height:250px; max-height:250px;">&lt;?php
	srand((double)microtime()*1000000);  		

	function randomString($size) { 
		$chars = "abcdefghijklmnopqrstuvwxyz"; //0123456789"; 
		$count = strlen($chars);
  		$i = 0;
  		$retval = ""; 
		while ($i &lt;= $size) { 
			$num = rand() % $count; 
			$char = substr($chars, $num, 1); 
			$retval = $retval . $char; 
			$i++; 
		} 
		return $retval;
	} 

	function randomSuffix() {
		$suffixes = array("com", "net", "org", "biz", "info", "name", "fr", 
                                  "de", "it", "co.uk", "ch", "ru", "tv", "info");
		$idx = rand() % count($suffixes);
		return $suffixes[$idx];
	}

	function randomEmail() {
		$name = randomString(rand(5,10));
		$surname = randomString(rand(5,10));
		$domain = randomString(rand(5,10));
		$suffix = randomSuffix();
		$mailType = rand() % 2;
		if ($mailType == 0) {
			return $name . "." . $surname . "@" . $domain . "." . $suffix;
		} else {
			return $name . "@" . $domain . "." . $suffix;
		}
	}
	
	function doMail() {
		$emailPerPage = 50;
		for ($emailCount = 0; $emailCount &lt; $emailPerPage; $emailCount++) { 
			$email = randomEmail();
			print("\t\t&lt;a href=\"mailto:");
			print($email);
			print("\"&gt;");
			print($email);
			print("&lt;/a&gt;&lt;br&gt;\n");
		}	
	}
	
?&gt;

&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;&lt;?= randomString(10) ?&gt;&lt;/title&gt;
	&lt;/head&gt;
	&lt;body&gt;

&lt;?php 
    doMail();
?&gt;
		&lt;br&gt;
		Not enough? 
		&lt;a href="emails.php?&lt;?= randomString(5) ?&gt;=&lt;?= rand(0,9999999) ?&gt;"&gt;
			Get more!
		&lt;/a&gt;&lt;br&gt;

	&lt;/body&gt;
&lt;/html&gt;
</pre>

<p>
A spambot could fall in loop, as at the end of the page there's a link to the page itself (with a random parameter to try avoiding the spambot to understand that the page is the same; with servlet this could be accomplished better).<br/>
In the top and the bottom of every page I simply put some hidden links (the text of the link is a transparent 1x1 pixel sized gif or just a non printable blank space) to the garbage-email-page (self-linking to make spambot loop infinitely).<br/>
You can notice that from the user point of view it's completely invisible, but the html source does the trick.<br />

In this way the real user browsing your site is completely unaware of anti spam measures you used to protect your email address. <br/>
I am thinking on a javascript that browse the content of the current page using regular expression to search text like "name at domain dot com" replacing it with fully readable and clickable mailto:// links. I googled a little to find a script like this but I didn't find, so I think I'll do myself if I'll have some spare time for it.<br/>
Someone has to report more (or better) anti-spam techniques to protect email in web sites? If yes, I'll add to this post.</p><div id="crp_related"><h4>Related Posts:</h4><ul><li><a href="http://en.newinstance.it/2005/06/17/adding-hidden-fields-to-a-form/" rel="bookmark" class="crp_title">Adding hidden fields to a Form</a></li><li><a href="http://en.newinstance.it/2005/06/11/infamous-programming-errors-on-curly-braced-blocks/" rel="bookmark" class="crp_title">Infamous programming errors on curly braced {blocks}</a></li><li><a href="http://en.newinstance.it/2005/07/11/webwork-package-configuration-problem/" rel="bookmark" class="crp_title">Webwork Package Configuration Problem</a></li><li><a href="http://en.newinstance.it/2005/07/11/hibernate-and-database-views/" rel="bookmark" class="crp_title">Hibernate and Database Views</a></li><li><a href="http://en.newinstance.it/2008/10/24/always-on-getter-and-setters/" rel="bookmark" class="crp_title">Always on getter and setters</a></li></ul></div><div class="shr-publisher-169"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F06%2F13%2Fanti-spam-email-hiding-techniques%2F' data-shr_title='Anti+spam+email+hiding+techniques'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F06%2F13%2Fanti-spam-email-hiding-techniques%2F' data-shr_title='Anti+spam+email+hiding+techniques'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F06%2F13%2Fanti-spam-email-hiding-techniques%2F' data-shr_title='Anti+spam+email+hiding+techniques'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2005/06/13/anti-spam-email-hiding-techniques/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Automatic Proxy Switching</title>
		<link>http://en.newinstance.it/2005/06/11/automatic-proxy-switching/</link>
		<comments>http://en.newinstance.it/2005/06/11/automatic-proxy-switching/#comments</comments>
		<pubDate>Sat, 11 Jun 2005 15:18:48 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Lifehacks]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://it.newinstance.it/2005/06/11/automatic-proxy-switching/</guid>
		<description><![CDATA[Working with my laptop on different places I often have to configure network settings. Fortunately I always work on places using DHCP, so this isn&#8217;t an issue. But I&#8217;ve still to waste time switching the proxy settings in browsers (IE, Firefox, Opera, Maxthon&#8230;). Of course there are plugins that handle proxy switching with less effort, [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic -->Working with my laptop on different places I often have to configure network settings. Fortunately I always work on places using DHCP, so this isn&#8217;t an issue. But I&#8217;ve still to waste time switching the proxy settings in browsers (IE, Firefox, Opera, Maxthon&#8230;). Of course there are plugins that handle proxy switching with less effort, but you have to do it manually, and instead it would be great to do it automatically. Every browser do this, automatically, without needing a plugin.</p>
<p>To do that, you have to create a file called proxy.pac in your filesystem, like this one:</p>
<pre class="code"><span class="line_number"> 1</span><span class="code">function FindProxyForURL<span class="parenthesis">(</span>url, host<span class="parenthesis">)</span>
<span class="line_number"> 2</span><span class="parenthesis">{</span>
<span class="line_number"> 3</span>    <span class="java_keyword">if</span> <span class="parenthesis">(</span> dnsDomainIs<span class="parenthesis">(</span>host, <span class="string_constant">&quot;localhost&quot;</span><span class="parenthesis">)</span> ||
<span class="line_number"> 4</span>         isPlainHostName<span class="parenthesis">(</span>host<span class="parenthesis">)</span> ||
<span class="line_number"> 5</span>         isInNet<span class="parenthesis">(</span>host, <span class="string_constant">&quot;127.0.0.1&quot;</span>, <span class="string_constant">&quot;255.255.255.255&quot;</span><span class="parenthesis">)</span> <span class="parenthesis">)</span>
<span class="line_number"> 6</span>        <span class="java_keyword">return</span> <span class="string_constant">&quot;DIRECT&quot;</span>;
<span class="line_number"> 7</span>
<span class="line_number"> 8</span>    <span class="java_keyword">if</span> <span class="parenthesis">(</span>isInNet<span class="parenthesis">(</span>myIpAddress<span class="parenthesis">()</span>, <span class="string_constant">&quot;192.168.0.0&quot;</span>, <span class="string_constant">&quot;255.255.0.0&quot;</span><span class="parenthesis">))</span>  <span class="comment_line">// HOME</span>
<span class="line_number"> 9</span>        <span class="java_keyword">return</span> <span class="string_constant">&quot;DIRECT&quot;</span>;
<span class="line_number">10</span>
<span class="line_number">11</span>    <span class="java_keyword">if</span> <span class="parenthesis">(</span>isInNet<span class="parenthesis">(</span>myIpAddress<span class="parenthesis">()</span>, <span class="string_constant">&quot;10.1.0.0&quot;</span>, <span class="string_constant">&quot;255.255.0.0&quot;</span><span class="parenthesis">))</span>  <span class="comment_line">// CLIENT 1</span>
<span class="line_number">12</span>        <span class="java_keyword">return</span> <span class="string_constant">&quot;PROXY web-proxy:8080&quot;</span>;
<span class="line_number">13</span><span class="parenthesis">}</span></span>
</pre>
<p>This means: when I connect to localhost or to 127.0.0.1 the browser will not have to use any proxy, going DIRECT.<br />
When myIp is in 192.168.*.* don&#8217;t use any proxy (as I am @ home). When my ip is 10.1.*.* use &#8220;web-proxy:8080&#8243;, and so on&#8230;<br />
The 255.255.0.0 is the net mask. 255 means perfect match, 0 means &#8216;anything&#8217; matches (like &#8220;*&#8221; wildcard).</p>
<p>Once you created this file you go on &#8220;Firefox->Connection Settings->Automatic Proxy Configuration URL&#8221; and set the path of the proxy.pac file as in this sample: file:///C:/Windows/proxy.pac<br />
Notice that (for mozilla) you have 3 slash.<br />
Using IE, you set it on connection settings as this file://C:\Windows\proxy.pac.<br />
For Opera you set automatic proxy configuration with something like file://C:/Windows/proxy.pac</p>
<p>Then and for the next, when browsing the javascript will be executed and the correct proxy will be automatically selected.</p>
<p>Many apps also get internet settings by IE, so this works well for many apps (MSN messenger, for example). Some others don&#8217;t (i.e. gaim, eclipse&#8230;). So you still have to do something manually.<br />
Warning: Google Web Accelerator, overwrites proxy settings in IE,using its own proxy.pac file. I won&#8217;t use it until they fix this.</p>
<p>There are several tools like <a href="http://www.netswitcher.com/">NetSwitcher</a> that handle this issue, but they can&#8217;t handle any rebellious apps (like gaim and eclipse&#8230;).
<div id="crp_related">
<h4>Related Posts:</h4>
<ul>
<li><a href="http://en.newinstance.it/2008/11/04/dynamic-tests-with-junit-3/" rel="bookmark" class="crp_title">Dynamic tests with JUnit 3</a></li>
<li><a href="http://en.newinstance.it/2008/10/24/always-on-getter-and-setters/" rel="bookmark" class="crp_title">Always on getter and setters</a></li>
<li><a href="http://en.newinstance.it/2008/10/24/the-repetita-juvant-principle/" rel="bookmark" class="crp_title">The Repetita Juvant Principle</a></li>
<li><a href="http://en.newinstance.it/2006/11/19/reading-javadocs-from-inside-the-original-zip-file/" rel="bookmark" class="crp_title">Reading Javadocs from inside the original zip file</a></li>
<li><a href="http://en.newinstance.it/2008/11/22/random-thoughts-about-unchecked-exceptions/" rel="bookmark" class="crp_title">Random thoughts about unchecked exceptions</a></li>
</ul>
</div>
<div class="shr-publisher-217"></div>
<p><!-- Start Shareaholic LikeButtonSetBottom Automatic -->
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F06%2F11%2Fautomatic-proxy-switching%2F' data-shr_title='Automatic+Proxy+Switching'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F06%2F11%2Fautomatic-proxy-switching%2F' data-shr_title='Automatic+Proxy+Switching'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F06%2F11%2Fautomatic-proxy-switching%2F' data-shr_title='Automatic+Proxy+Switching'></a></div>
<div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div>
<p><!-- End Shareaholic LikeButtonSetBottom Automatic --></p>
]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2005/06/11/automatic-proxy-switching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Progress bar while computing&#8230;</title>
		<link>http://en.newinstance.it/2005/06/11/progress-bar-while-computing/</link>
		<comments>http://en.newinstance.it/2005/06/11/progress-bar-while-computing/#comments</comments>
		<pubDate>Sat, 11 Jun 2005 08:50:54 +0000</pubDate>
		<dc:creator>Luigi</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://it.newinstance.it/2005/06/11/progress-bar-while-computing/</guid>
		<description><![CDATA[I found this nice javascript that could be useful in places where some computing may take some time... Many application do intensive searches or computations, and it's better to give some feedback to the user while loading the results. You can try displaying a page with an animated GIF, and redirecting the page using something [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>I found this nice javascript that could be useful in places where some computing may take some time... Many application do intensive searches or computations, and it's better to give some feedback to the user while loading the results.
You can try displaying a page with an animated GIF, and redirecting the page using something like:</p>

<pre style="min-height:0px;">
  &lt;meta http-equiv="Refresh" content="0; URL="result-url"&gt;
</pre>

<p>But when the browser (IE) sends the request to "result-url", the GIF stops! Animated GIFs, seems to work for this purpose on Firefox and Opera, but not IE.<br/>
Here's a JavaScript solution:
</p>

<pre>
&lt;script language="javascript" type="text/javascript"&gt;
    var SIZE=240;
    var STEP=2;
    window.onload = progress;
    function progress(){
        var bar=document.getElementById('progressbar');
        bar.style.width=(parseInt(bar.style.width)+STEP)%SIZE;
        setTimeout('progress()',40);		
    }
&lt;/script&gt;
&lt;div id="progressbar" 
     style="width:0px;height:10px;background-color:red;"&gt;&lt;/div&gt;
</pre>

<p>
Displaying an animated image could be easy replacing the "src" of an &lt;img&gt; element. 
I saw this technique by the JOnAS administrative console to reload periodically a server-side generated image that represent a graph of memory consumption. 
It just reload the image, without reloading the page. At first look it could seem an applet, but it isn't.</p>
<div id="crp_related"><h4>Related Posts:</h4><ul><li><a href="http://en.newinstance.it/2006/09/27/client-side-html-table-pagination-with-javascript/" rel="bookmark" class="crp_title">Client-side HTML table pagination with JavaScript</a></li><li><a href="http://en.newinstance.it/2005/06/13/anti-spam-email-hiding-techniques/" rel="bookmark" class="crp_title">Anti spam email hiding techniques</a></li><li><a href="http://en.newinstance.it/2005/06/17/adding-hidden-fields-to-a-form/" rel="bookmark" class="crp_title">Adding hidden fields to a Form</a></li><li><a href="http://en.newinstance.it/2006/10/31/email-url-encoder-tool/" rel="bookmark" class="crp_title">Email URL Encoder Tool</a></li><li><a href="http://en.newinstance.it/2010/04/09/how-gwt-is-useful-in-place-of-javascript-and-css/" rel="bookmark" class="crp_title">How GWT is useful in place of  Javascript and CSS?</a></li></ul></div><div class="shr-publisher-179"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F06%2F11%2Fprogress-bar-while-computing%2F' data-shr_title='Progress+bar+while+computing...'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F06%2F11%2Fprogress-bar-while-computing%2F' data-shr_title='Progress+bar+while+computing...'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fen.newinstance.it%2F2005%2F06%2F11%2Fprogress-bar-while-computing%2F' data-shr_title='Progress+bar+while+computing...'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://en.newinstance.it/2005/06/11/progress-bar-while-computing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

