<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Marcel's Webpage</title>
	<atom:link href="http://marcelpad.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://marcelpad.wordpress.com</link>
	<description></description>
	<lastBuildDate>Wed, 28 Dec 2011 22:37:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='marcelpad.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Marcel's Webpage</title>
		<link>http://marcelpad.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://marcelpad.wordpress.com/osd.xml" title="Marcel&#039;s Webpage" />
	<atom:link rel='hub' href='http://marcelpad.wordpress.com/?pushpress=hub'/>
		<item>
		<title>From Singapore to Melbourne and Job Hunting</title>
		<link>http://marcelpad.wordpress.com/2009/09/17/from-singapore-to-melbourne-and-job-hunting/</link>
		<comments>http://marcelpad.wordpress.com/2009/09/17/from-singapore-to-melbourne-and-job-hunting/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 16:57:24 +0000</pubDate>
		<dc:creator>marcelpad</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://marcelpad.wordpress.com/?p=204</guid>
		<description><![CDATA[As most know I moved from Melbourne to Singapore at the end of 2008. It is now time to move back to Melbourne and experience four seasons in a day! My time in Singapore so far has been a really good learning experience. I have been the lead for doQer, a startup launched by Remarkable [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcelpad.wordpress.com&amp;blog=2231039&amp;post=204&amp;subd=marcelpad&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img src="http://marcelpad.files.wordpress.com/2009/09/citycircle1.jpg?w=150&#038;h=99" alt="Melbourne&#39;s City Circle Tram" title="Melbourne&#39;s City Circle Tram" width="150" height="99" class="alignleft size-thumbnail wp-image-216" />As most know I moved from Melbourne to Singapore at the end of 2008. It is now time to move back to Melbourne and experience four seasons in a day!</p>
<p>My time in Singapore so far has been a really good learning experience. I have been the lead for <a href="http://www.doQer.com">doQer</a>, a startup launched by <a href="http://remarkableinnovation.com/">Remarkable Innovation</a>. It is really exciting as it makes it easy for people to manage and view user manuals. No more downloading huge PDF files and not find the information you were looking for, or being stuck in a flash window inside your browser.</p>
<p>I have been priviledged to have a lot of say in giving direction to the project alongside Mark Reilly. Don&#8217;t mind my beloved and super comfortable <a href="http://en.wikipedia.org/wiki/Aeron_chair">Aeron Chair</a> (my back thanks you), or really nice dual monitor setup. Finally I was able to mold my development practices to the <a href="http://www.joelonsoftware.com/articles/fog0000000043.html">Joel Test</a>.</p>
<p>For those who don&#8217;t know the <a href="http://www.joelonsoftware.com/articles/fog0000000043.html">Joel Test</a>, it is a list of good practices a Software company should have:</p>
<blockquote><p>
   1. Do you use source control?<br />
   2. Can you make a build in one step?<br />
   3. Do you make daily builds?<br />
   4. Do you have a bug database?<br />
   5. Do you fix bugs before writing new code?<br />
   6. Do you have an up-to-date schedule?<br />
   7. Do you have a spec?<br />
   8. Do programmers have quiet working conditions?<br />
   9. Do you use the best tools money can buy?<br />
  10. Do you have testers?<br />
  11. Do new candidates write code during their interview?<br />
  12. Do you do hallway usability testing?
</p></blockquote>
<p>I must confess that not all items were ticked off, specially since lots don&#8217;t apply to web development. However it is very (very much) satisfying to see development moving to have more solid practices put in place!</p>
<p>Now with my moving back to Melbourne I have to start job hunting. A browse for jobs in <a href="http://www.seek.com.au">Seek</a> was not very exciting. The <a href="http://jobs.stackoverflow.com/">jobs section</a> at Stack Overflow seems like a better place to start. Too bad most jobs are in the United States.</p>
<p>I am determined to take the inverse approach, find an awesome work place and drop them a note instead.</p>
<p>I would love to know what companies have good development practices in Melbourne. Would appreciate if anyone could drop me a note in the comments, or in this <a href="http://forums.whirlpool.net.au/forum-replies.cfm?t=1282966">thread</a> I started in Whirlpool!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marcelpad.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marcelpad.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marcelpad.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marcelpad.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/marcelpad.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/marcelpad.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/marcelpad.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/marcelpad.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marcelpad.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marcelpad.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marcelpad.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marcelpad.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marcelpad.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marcelpad.wordpress.com/204/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcelpad.wordpress.com&amp;blog=2231039&amp;post=204&amp;subd=marcelpad&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marcelpad.wordpress.com/2009/09/17/from-singapore-to-melbourne-and-job-hunting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Marcel</media:title>
		</media:content>

		<media:content url="http://marcelpad.files.wordpress.com/2009/09/citycircle1.jpg?w=150" medium="image">
			<media:title type="html">Melbourne&#039;s City Circle Tram</media:title>
		</media:content>
	</item>
		<item>
		<title>Spam</title>
		<link>http://marcelpad.wordpress.com/2008/11/07/spam/</link>
		<comments>http://marcelpad.wordpress.com/2008/11/07/spam/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 22:02:18 +0000</pubDate>
		<dc:creator>marcelpad</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://marcelpad.wordpress.com/?p=150</guid>
		<description><![CDATA[Must be my lucky day? It must be a sign. I am scared!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcelpad.wordpress.com&amp;blog=2231039&amp;post=150&amp;subd=marcelpad&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Must be my lucky day? </p>
<p><a href="http://marcelpad.files.wordpress.com/2008/11/spam_6662.jpg"><img src="http://marcelpad.files.wordpress.com/2008/11/spam_6662.jpg?w=300&#038;h=195" alt="Askimet has caught 666 spam" title="Askimet has caught 666 spam" width="300" height="195" class="size-medium wp-image-149" /></a></p>
<p>It must be a sign. I am scared!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marcelpad.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marcelpad.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marcelpad.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marcelpad.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/marcelpad.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/marcelpad.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/marcelpad.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/marcelpad.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marcelpad.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marcelpad.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marcelpad.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marcelpad.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marcelpad.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marcelpad.wordpress.com/150/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcelpad.wordpress.com&amp;blog=2231039&amp;post=150&amp;subd=marcelpad&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marcelpad.wordpress.com/2008/11/07/spam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Marcel</media:title>
		</media:content>

		<media:content url="http://marcelpad.files.wordpress.com/2008/11/spam_6662.jpg?w=300" medium="image">
			<media:title type="html">Askimet has caught 666 spam</media:title>
		</media:content>
	</item>
		<item>
		<title>Joining an Open Source Project</title>
		<link>http://marcelpad.wordpress.com/2008/10/15/joining-an-open-source-project/</link>
		<comments>http://marcelpad.wordpress.com/2008/10/15/joining-an-open-source-project/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 02:58:44 +0000</pubDate>
		<dc:creator>marcelpad</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://marcelpad.wordpress.com/?p=45</guid>
		<description><![CDATA[So I have decided to dedicate part of my free time working on an open source project. Right. No problems coming up with that, but what should I look for and where should I start? After doing my reading I decided on two main selling points for me to join a project: Fun and Something-I-Would-Use [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcelpad.wordpress.com&amp;blog=2231039&amp;post=45&amp;subd=marcelpad&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So I have decided to dedicate part of my free time working on an open source project.</p>
<p>Right. No problems coming up with that, but what should I look for and where should I start?</p>
<p>After doing my reading I decided on two main selling points for me to join a project: <strong>Fun</strong> and <strong>Something-I-Would-Use</strong></p>
<p>The first part was easy. Of course it should be fun! It is something I am going to be spending my free time on.</p>
<p>The big contributor to the fun part is doing something that is interesting to me. Although coding itself is already enjoyable, working on something compelling will get me going. How many times have I not gotten too excited explaining how I solved a problem or fixed a bug, when a person expected a simple answer by asking how my day was.</p>
<p><a href="http://www.sauria.com/blog/">Ted Leung</a> was talking about people who joins open source projects in the <a href="http://herdingcode.com">Herding Code</a> podcast:</p>
<blockquote><p>In general the whole thing with open source is you let people work in what they are interested in. They will probably gravitate towards what they are interested in and what they are good at. That means their quality of work will be a lot higher.</p></blockquote>
<p>I agree. If working with something that interests me will generate quality output, and I get some fun out of it; I am happy with that!</p>
<p>Now the Something-I-Would-Use part. I came to that conclusion reading a <a href="http://steve-yegge.blogspot.com/2008/08/business-requirements-are-bullshit.html">post</a> on <a href="http://steve-yegge.blogspot.com">Steve Yegge&#8217;s blog</a> which was not on joining open source projects, but I believe is still applicable to this situation:</p>
<blockquote><p>So when translated into project selection, Buffett&#8217;s and Lynch&#8217;s advice becomes: only build what you know. The longer, more accurate of the version of the investing rule — only invest in what you know and are excited about using yourself right now — has a simpler formulation for products and businesses.</p></blockquote>
<p>Steve was talking about how software requirements are unimportant (not <em>exactly</em> the word he used). Specially if you are working on something that you use, because you know what the requirements are.</p>
<p>Again, I totally agree. People should join a project of a product they use in their own time. It will benefit from the current knowledge and experience of how the product should behave.</p>
<p>So now I am off to <a href="http://code.google.com/">Google Code</a>, <a href="https://sourceforge.net">Sourceforge</a>, and <a href="http://freshmeat.net/">Freshmeat</a> to find a project that is fun and it is something-I-would-use.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marcelpad.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marcelpad.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marcelpad.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marcelpad.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/marcelpad.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/marcelpad.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/marcelpad.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/marcelpad.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marcelpad.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marcelpad.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marcelpad.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marcelpad.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marcelpad.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marcelpad.wordpress.com/45/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcelpad.wordpress.com&amp;blog=2231039&amp;post=45&amp;subd=marcelpad&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marcelpad.wordpress.com/2008/10/15/joining-an-open-source-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Marcel</media:title>
		</media:content>
	</item>
		<item>
		<title>A Simple AJAX Example: Searching Australian Postcodes (with JQuery)</title>
		<link>http://marcelpad.wordpress.com/2008/07/09/a-simple-ajax-example-searching-australian-postcodes-now-with-jquery/</link>
		<comments>http://marcelpad.wordpress.com/2008/07/09/a-simple-ajax-example-searching-australian-postcodes-now-with-jquery/#comments</comments>
		<pubDate>Wed, 09 Jul 2008 02:04:29 +0000</pubDate>
		<dc:creator>marcelpad</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[australian]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[postcode]]></category>

		<guid isPermaLink="false">http://marcelpad.wordpress.com/?p=34</guid>
		<description><![CDATA[Lately I have been writing dashlets for the SugarCRM open source CRM solution. It uses JQuery as part of its JavaScript libraries. I have really been enjoying writing JavaScript with JQuery; it has saved me time writing concise code which also helps me debug and maintain it. So I thought it would be a good [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcelpad.wordpress.com&amp;blog=2231039&amp;post=34&amp;subd=marcelpad&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Lately I have been writing dashlets for the <a href="http://www.sugarcrm.com/">SugarCRM</a> open source CRM solution. It uses <a href="http://jquery.com/">JQuery</a> as part of its JavaScript libraries.</p>
<p>I have really been enjoying writing JavaScript with JQuery; it has saved me time writing concise code which also helps me debug and maintain it. So I thought it would be a good idea to rewrite my Ajax example with JQuery to compare its usefulness.</p>
<p>In my previous code I had to first create the XMLHttpRequest object:</p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;"><font color='Blue'>var</font> xmlHttpReq;   

<font color='Green'>// Determining which browser we are dealing with </font>
<font color='Blue'>if</font> (window.XMLHttpRequest)
{
   xmlHttpReq = <font color='Blue'>new</font> XMLHttpRequest();
   xmlHttpReq.overrideMimeType(<font color='Maroon'>'text/plain'</font>);
}
<font color='Blue'>else</font> <font color='Blue'>if</font> (window.ActiveXObject)
{
   <font color='Green'>// this is required if the browser is IE</font>
   xmlHttpReq = <font color='Blue'>new</font> ActiveXObject(<font color='Maroon'>"Microsoft.XMLHTTP"</font>);
}</pre>
<p>Then I had to prepare the query string and post to the script that would get the me the details:</p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;"><font color='Green'>// generate the query string to post to the script</font>
<font color='Blue'>var</font> queryStr = <font color='Maroon'>'PostCode='</font> + escape(postcode);

<font color='Blue'>var</font> strURL = <font color='Maroon'>'postcode_lookup.php'</font>;

xmlHttpReq.open(<font color='Maroon'>'GET'</font>, strURL, <font color='Maroon'>true</font>);
xmlHttpReq.setRequestHeader(<font color='Maroon'>'Content-Type'</font>, <font color='Maroon'>'application/x-www-form-urlencoded'</font>);
xmlHttpReq.onreadystatechange = displayPostcode;

<font color='Green'>// post to script</font>
xmlHttpReq.send(queryStr);
</pre>
<p>That is too much work! With JQuery things are much easier:</p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;">$.<font color='Blue'>get</font>(<font color='Maroon'>"postcode_lookup.php"</font>,
      { PostCode: jQuery(<font color='Maroon'>'input[@name=PostCode]'</font>)[<font color='Maroon'>0</font>].value },
      <font color='Blue'>function</font>(data)
      {
         <font color='Green'>/* Logic to parse data and determine output goes here */</font>

         <font color='Green'>// Writing output into div</font>
         $(<font color='Maroon'>"#outputDiv"</font>).html(output);
      }
);
</pre>
<p>That&#8217;s it! All it takes is one function to make the Ajax call and then parse the data from the script.</p>
<p>The <em>jQuery.get( url, [data], [callback], [type] ) </em> function takes four parameters. But we are only using three as the last one is optional:<br />
1. The script: postcode_lookup.php.<br />
2. The parameters for the script contained in an array. In this case the value of the text field:<br />
{ PostCode: jQuery(‘input[@name=PostCode]‘)[0].value }<br />
3. The callback function to handle the data returned from the script.</p>
<p>I am quite happy for the amount of work that it has saved me. However I cannot emphasize enough how important it is to understand how the XMLHttpRequest works. </p>
<p>You can find the working example <a href="http://puiching.customer.netspace.net.au/apps/postcodesearch_jquery/">here</a>.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/marcelpad.wordpress.com/34/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/marcelpad.wordpress.com/34/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marcelpad.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marcelpad.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marcelpad.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marcelpad.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/marcelpad.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/marcelpad.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/marcelpad.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/marcelpad.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marcelpad.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marcelpad.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marcelpad.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marcelpad.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marcelpad.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marcelpad.wordpress.com/34/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcelpad.wordpress.com&amp;blog=2231039&amp;post=34&amp;subd=marcelpad&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marcelpad.wordpress.com/2008/07/09/a-simple-ajax-example-searching-australian-postcodes-now-with-jquery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Marcel</media:title>
		</media:content>
	</item>
		<item>
		<title>Finding the closest Melbourne CBD train station with GDirections</title>
		<link>http://marcelpad.wordpress.com/2008/03/04/finding-the-closest-melbourne-cbd-train-station-with-gdirections/</link>
		<comments>http://marcelpad.wordpress.com/2008/03/04/finding-the-closest-melbourne-cbd-train-station-with-gdirections/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 04:44:35 +0000</pubDate>
		<dc:creator>marcelpad</dc:creator>
				<category><![CDATA[Google Maps]]></category>

		<guid isPermaLink="false">http://marcelpad.wordpress.com/?p=24</guid>
		<description><![CDATA[This application came from my dependence on public transport and possible need to move houses; I wanted to know how close I would be in relation to train stations. There are quite a number of stations in Melbourne, and I don’t have the time to map all of their coordinates, so at the time being [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcelpad.wordpress.com&amp;blog=2231039&amp;post=24&amp;subd=marcelpad&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.marcelzeng.com/blog/apps/closest_station' title='Finding the closest Melbourne CBD train station with GDirections'><img src='http://marcelpad.files.wordpress.com/2008/03/20080304.jpg?w=500' alt='Finding the closest Melbourne CBD train station with GDirections' /></a></p>
<p>This <a href="http:///www.marcelzeng.com/apps/closest_station">application</a> came from my dependence on public transport and possible need to move houses; I wanted to know how close I would be in relation to train stations. There are quite a number of stations in Melbourne, and I don’t have the time to map all of their coordinates, so at the time being it only has train stations from the City Loop.</p>
<p>The application uses <em>GDirections</em>. It lets us load way points and retrieve the route details; such as distance, driving directions, and even an HTML summary of the travel.</p>
<p>I used <em>GDirections</em> in two instances of the application:<br />
1. To determine the distance between my pivot position and the train stations.<br />
2. To plot the route of my pivot point to the closest train station</p>
<p><span id="more-24"></span></p>
<p>In both instances I used <em>GDirections</em> in the same way:</p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;"><code><font color='Blue'>var</font> directions = <font color='Blue'>new</font> GDirections();

<font color='Green'>// Put pivot location and the selected train station into an array   </font>
<font color='Blue'>var</font> lArray = <font color='Blue'>new</font> Array();
lArray.push( start );
lArray.push( end );

<font color='Green'>// Load route from pivot location to train station</font>
directions.loadFromWaypoints(lArray);</code></pre>
<p>After I loaded the way points it is possible to retrieve information such as the distance in meters:</p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;">directions.getDistance().meters</code></pre>
<p>However I ran into a problem: I was loading the way points but it was returning me <em>NULL</em>. That is because the loading is done asynchronously, so to retrieve the details we have to wait until it loads completely. To do that we create an event listener:</p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;"><code>GEvent.addListener(directions,<font color='Maroon'>"load"</font>, <font color='Blue'>function</font>()
{
   <font color='Green'>// Here directions should not be NULL</font>
   <font color='Blue'>var</font> distance = directions.getDistance().meters;
});  </code></pre>
<p>After we calculate the shortest distance, we are ready to render the route on the map. To do that I passed the map as an argument when initialising <em>GDirections</em>.</p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;"><code><font color='Green'>// Clear map and panel</font>
map.clearOverlays();

<font color='Blue'>var</font> directions = <font color='Blue'>new</font> GDirections(map);

<font color='Green'>// Array with the shortest route</font>
<font color='Blue'>var</font> lArray = <font color='Blue'>new</font> Array();
lArray.push( start );
lArray.push( end );

directions.loadFromWaypoints(lArray , {preserveViewport: <font color='Maroon'>true</font>});</code></pre>
<p>Note that I used the <em>preserveViewport</em> option. That is so the map won’t change zoom or position when rendering the route.</p>
<p>Please drop me a message if anyone knows where I can find free coordinates of the train stations, and I will add them to the application.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/marcelpad.wordpress.com/24/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/marcelpad.wordpress.com/24/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marcelpad.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marcelpad.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marcelpad.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marcelpad.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/marcelpad.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/marcelpad.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/marcelpad.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/marcelpad.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marcelpad.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marcelpad.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marcelpad.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marcelpad.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marcelpad.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marcelpad.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcelpad.wordpress.com&amp;blog=2231039&amp;post=24&amp;subd=marcelpad&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marcelpad.wordpress.com/2008/03/04/finding-the-closest-melbourne-cbd-train-station-with-gdirections/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Marcel</media:title>
		</media:content>

		<media:content url="http://marcelpad.files.wordpress.com/2008/03/20080304.jpg" medium="image">
			<media:title type="html">Finding the closest Melbourne CBD train station with GDirections</media:title>
		</media:content>
	</item>
		<item>
		<title>Adding Markers on Google Maps (with more functionalities)</title>
		<link>http://marcelpad.wordpress.com/2007/12/27/extended-google-map-markers/</link>
		<comments>http://marcelpad.wordpress.com/2007/12/27/extended-google-map-markers/#comments</comments>
		<pubDate>Thu, 27 Dec 2007 03:48:03 +0000</pubDate>
		<dc:creator>marcelpad</dc:creator>
				<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[custom icon]]></category>
		<category><![CDATA[event listener]]></category>
		<category><![CDATA[info window]]></category>
		<category><![CDATA[marker]]></category>

		<guid isPermaLink="false">http://marcelpad.wordpress.com/2007/12/27/extended-google-map-markers/</guid>
		<description><![CDATA[I modified my previous markers example to show off further functionalities: To pop up an info window with marker description. To handle clicks and create new markers. To use markers with custom images. To pop up an info window with marker description Google maps handles clicks through event listeners. Thus, to open the info window [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcelpad.wordpress.com&amp;blog=2231039&amp;post=23&amp;subd=marcelpad&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I <a href="http://marcelzeng.com/blog/apps/googlemap_markers/index_extended.html">modified</a> my previous markers example to show off further functionalities:</p>
<ul>
<li>To pop up an info window with marker description.</li>
<li>To handle clicks and create new markers.</li>
<li>To use markers with custom images.</li>
</ul>
<p><a href='http://marcelzeng.com/blog/apps/googlemap_markers/index_extended.html' title='Extended Google Map Markers'><img src='http://marcelpad.files.wordpress.com/2007/12/20071215.jpg?w=500' alt='Extended Google Map Markers' /></a></p>
<p><span id="more-23"></span></p>
<p><strong>To pop up an info window with marker description</strong><br />
Google maps handles clicks through event listeners. Thus, to open the info window we use the <em>GEvent</em> object:</p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;">GEvent.addListener(marker, <font color='Maroon'>'click'</font>,
      <font color='Blue'>function</font>()
      {
         <font color='Blue'>var</font> htmlString = "&lt;font color=\"#<font color='Maroon'>6387</font>A5\" size=\"<font color='Maroon'>1</font>\"
                                 face=\<font color='Maroon'>"Verdana, Arial, Helvetica, sans-serif\"&gt;"</font>+
                          description+<font color='Maroon'>"&lt;br/&gt;"</font> +
                          <font color='Maroon'>"("</font> + latitude + <font color='Maroon'>","</font> + longitude + <font color='Maroon'>")&lt;/font&gt;"</font>;
         marker.openInfoWindowHtml(htmlString);
      }
   );</pre>
<p>The <em>addListener</em> method takes your marker, event type, and a callback function. The callback function is executed when the event is fired, and it calls <em>marker.openInfoWindowHtml</em> which opens an info window.</p>
<p>We also pass a string with the openInfoWindowHtml method, which will be displayed in the info window.</p>
<p><strong>To handle clicks and create new markers</strong><br />
We also handle clicks on the map with <em>GEvent</em>, but this time we add a listener by passing the map instead of the marker:</p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;">GEvent.addListener(map, <font color='Maroon'>"click"</font>, <font color='Blue'>function</font>(overlay, location) {

         <font color='Blue'>if</font>( overlay )
         {
            <font color='Green'>// clicked on something other than the map</font>

         }
         <font color='Blue'>else</font>
         {
            <font color='Blue'>var</font> description = prompt(<font color='Maroon'>"Please enter marker description"</font>, <font color='Maroon'>""</font>);

            <font color='Green'>// create a new marker</font>
            <font color='Blue'>if</font>( description != <font color='Blue'>null</font> )
               addMarker(location,description);
         }

      });</pre>
<p>I had an issue that triggered the map event when clicking on an info window. Ideally we should be able to tell where the click came from, and handle the event appropriately. This is possible with the callback function taking two arguments: an overlay, and the coordinates of the click.</p>
<p>The first argument is the overlay that was clicked by the user; for example markers and info windows. Therefore, when the first argument is not an overlay we can safely say that the user clicked on the map.</p>
<p><strong>To use markers with custom images</strong></p>
<p>We use the <em>GIcon</em> object to create markers with custom images. Once we create an instance of <em>GIcon</em> we pass it into the <em>GMarker</em> constructor; displaying the custom image instead of the default marker.</p>
<p>In the example we randomly use one of the three custom markers:<br />
<img src="http://puiching.customer.netspace.net.au/apps/googlemap_markers/images/marker_green.png" alt="Green Marker" /><img src="http://puiching.customer.netspace.net.au/apps/googlemap_markers/images/marker_blue.png" alt="Blue Marker" /><img src="http://puiching.customer.netspace.net.au/apps/googlemap_markers/images/marker_yellow.png" alt="Yellow Marker" /></p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;"><font color='Green'>// create new gicon to use with the marker</font>
<font color='Blue'>var</font> customIcon = <font color='Blue'>new</font> GIcon();

<font color='Green'>// put in random image</font>
<font color='Blue'>var</font> pos = Math.floor(Math.random()*<font color='Maroon'>3</font>);
<font color='Blue'>var</font> images = <font color='Blue'>new</font> Array(<font color='Maroon'>"images/marker_green.png"</font>,
<font color='Maroon'>"images/marker_blue.png"</font>,
<font color='Maroon'>"images/marker_yellow.png"</font>);
customIcon.image = images[pos];

customIcon.iconSize = <font color='Blue'>new</font> GSize(<font color='Maroon'>20</font>, <font color='Maroon'>34</font>);
customIcon.iconAnchor = <font color='Blue'>new</font> GPoint(<font color='Maroon'>10</font>, <font color='Maroon'>34</font>);
customIcon.infoWindowAnchor = <font color='Blue'>new</font> GPoint(<font color='Maroon'>10</font>, <font color='Maroon'>0</font>);

<font color='Green'>// create new marker</font>
<font color='Blue'>var</font> marker = <font color='Blue'>new</font> GMarker(location,customIcon);</pre>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/marcelpad.wordpress.com/23/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/marcelpad.wordpress.com/23/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marcelpad.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marcelpad.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marcelpad.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marcelpad.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/marcelpad.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/marcelpad.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/marcelpad.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/marcelpad.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marcelpad.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marcelpad.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marcelpad.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marcelpad.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marcelpad.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marcelpad.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcelpad.wordpress.com&amp;blog=2231039&amp;post=23&amp;subd=marcelpad&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marcelpad.wordpress.com/2007/12/27/extended-google-map-markers/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Marcel</media:title>
		</media:content>

		<media:content url="http://marcelpad.files.wordpress.com/2007/12/20071215.jpg" medium="image">
			<media:title type="html">Extended Google Map Markers</media:title>
		</media:content>

		<media:content url="http://puiching.customer.netspace.net.au/apps/googlemap_markers/images/marker_green.png" medium="image">
			<media:title type="html">Green Marker</media:title>
		</media:content>

		<media:content url="http://puiching.customer.netspace.net.au/apps/googlemap_markers/images/marker_blue.png" medium="image">
			<media:title type="html">Blue Marker</media:title>
		</media:content>

		<media:content url="http://puiching.customer.netspace.net.au/apps/googlemap_markers/images/marker_yellow.png" medium="image">
			<media:title type="html">Yellow Marker</media:title>
		</media:content>
	</item>
		<item>
		<title>Adding Markers on Google Maps</title>
		<link>http://marcelpad.wordpress.com/2007/12/11/adding-markers-on-google-maps/</link>
		<comments>http://marcelpad.wordpress.com/2007/12/11/adding-markers-on-google-maps/#comments</comments>
		<pubDate>Tue, 11 Dec 2007 05:31:50 +0000</pubDate>
		<dc:creator>marcelpad</dc:creator>
				<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[Maps]]></category>
		<category><![CDATA[marker]]></category>

		<guid isPermaLink="false">http://marcelpad.wordpress.com/2007/12/11/adding-markers-on-google-maps/</guid>
		<description><![CDATA[I created an example of a Google Map application where you can plot markers on the map by specifying coordinates. Creating markers is fairly simple: 1. Create a new instance of GLatLng object. The GLatLng holds the coordinates of your marker. // create new location object var location = new GLatLng(latitude, longitude); 2. Create a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcelpad.wordpress.com&amp;blog=2231039&amp;post=18&amp;subd=marcelpad&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I created an <a href='http://marcelzeng.com/blog/apps/googlemap_markers' title='Google Map Markers'>example</a> of a Google Map application where you can plot markers on the map by specifying coordinates.</p>
<p><a href='http://marcelzeng.com/blog/apps/googlemap_markers' title='Google Map Markers'><img src='http://marcelpad.files.wordpress.com/2007/12/20071210.jpg?w=500' alt='Google Map Markers' /></a></p>
<p>Creating markers is fairly simple:</p>
<p>1. Create a new instance of <em>GLatLng</em> object. The <em>GLatLng</em> holds the coordinates of your marker.</p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;"><font color='Green'>// create new location object</font>
<font color='Blue'>var</font> location = <font color='Blue'>new</font> GLatLng(latitude, longitude);</pre>
<p>2. Create a new instance of <em>GMarker</em> with the <em>GLatLng</em> object.</p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;"><font color='Green'>// place new marker</font>
<font color='Blue'>var</font> marker = <font color='Blue'>new</font> GMarker(location);</pre>
<p>3. Use the <em>addOverlay</em> method to create a new overlay in the map.</p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;">map.addOverlay(marker);</pre>
<p>Just like we add an overlay to create a marker, we clear a marker by removing an overlay.</p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;">map.removeOverlay(markersArray[idx]);</pre>
<p>The <em>markersArray[idx]</em> is the <em>GMarker</em> we would like to remove. If you are not using an array to keep your markers, you can pass in an instance of <em>GMarker</em> directly.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/marcelpad.wordpress.com/18/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/marcelpad.wordpress.com/18/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marcelpad.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marcelpad.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marcelpad.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marcelpad.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/marcelpad.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/marcelpad.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/marcelpad.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/marcelpad.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marcelpad.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marcelpad.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marcelpad.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marcelpad.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marcelpad.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marcelpad.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcelpad.wordpress.com&amp;blog=2231039&amp;post=18&amp;subd=marcelpad&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marcelpad.wordpress.com/2007/12/11/adding-markers-on-google-maps/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Marcel</media:title>
		</media:content>

		<media:content url="http://marcelpad.files.wordpress.com/2007/12/20071210.jpg" medium="image">
			<media:title type="html">Google Map Markers</media:title>
		</media:content>
	</item>
		<item>
		<title>A Simple AJAX Example: Searching Australian Postcodes</title>
		<link>http://marcelpad.wordpress.com/2007/12/01/a-simple-ajax-example-searching-australian-postcodes/</link>
		<comments>http://marcelpad.wordpress.com/2007/12/01/a-simple-ajax-example-searching-australian-postcodes/#comments</comments>
		<pubDate>Sat, 01 Dec 2007 09:11:22 +0000</pubDate>
		<dc:creator>marcelpad</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[australian]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[postcode]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://marcelpad.wordpress.com/2007/12/04/a-simple-ajax-example-searching-australian-postcodes/</guid>
		<description><![CDATA[I have been trying out AJAX tools such as the YUI to make web applications more responsive. Reminding myself that AJAX stands for Asynchronous JavaScript and XML, I thought I’d try to understand better then asynchronous side of it. The xmlHttpReq object is responsible for the responsiveness of an AJAX application. It allows the JavaScript [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcelpad.wordpress.com&amp;blog=2231039&amp;post=15&amp;subd=marcelpad&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have been trying out AJAX tools such as the <a href="http://developer.yahoo.com/yui/">YUI</a> to make web applications more responsive. Reminding myself that AJAX stands for Asynchronous JavaScript and XML, I thought I’d try to understand better then asynchronous side of it.</p>
<p>The <em>xmlHttpReq</em> object is responsible for the responsiveness of an AJAX application. It allows the JavaScript to make asynchronous HTTP request (POST or GET) to a script. The same <em>xmlHttpReq</em> object handles the output of the script through a callback function.</p>
<p>The example that I wrote is an Australian postcode lookup. Basically, the user enters a postcode which is then posted by the <em>xmlHttpReq</em> object to a PHP script. The script returns comma delimited details of the postcode, which is processed by the callback function, and displayed nicely to the user.</p>
<p>Click <a href="http://marcelzeng.com/blog/apps/postcodesearch/" target="_blank">here</a> to see working example.</p>
<p><span id="more-15"></span></p>
<p><strong>The Query String</strong></p>
<p>We post the data to the script using a query string; the string will later be passed into the <em>xmlHttpReq</em> object.</p>
<p>In our case the data we post to the script is the postcode; for example ‘PostCode=3000&#8242;.</p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;"><font color='Blue'>var</font> postcode = document.forms[<font color='Maroon'>0</font>].PostCode.value;

<font color='Green'>// generate the query string to post to the script</font>
<font color='Blue'>var</font> queryStr = ‘PostCode=’ + escape(postcode);
</pre>
<p>It is possible to pass more variables with the query string; for example ‘PostCode=3000&amp;Location=Melbourne’.</p>
<p>Note that we encode the postcode when building the query string using the <em>escape</em> function.</p>
<p><strong>The xmlHttpReq Object</strong></p>
<p>Now it is time to create the <em>xmlHttpReq</em> object. We initialise it differently for Internet Explorer and Mozilla, thus we need to detect the user’s browser.</p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;"><font color='Blue'>var</font> xmlHttpReq;

<font color='Green'>// Determining which browser we are dealing with</font>
<font color='Blue'>if</font> (window.XMLHttpRequest)
{
   <font color='Green'>// this is required if the browser is Mozilla</font>
   xmlHttpReq = <font color='Blue'>new</font> XMLHttpRequest();
   xmlHttpReq.overrideMimeType(’text/plain’);
}
<font color='Blue'>else</font> <font color='Blue'>if</font> (window.ActiveXObject)
{
   <font color='Green'>// this is required if the browser is IE</font>
   xmlHttpReq = <font color='Blue'>new</font> ActiveXObject(”Microsoft.XMLHTTP”);
}
</pre>
<p>We can now set the parameters for the <em>xmlHttpReq</em> object. The <em>open</em> function takes three parameters: HTTP request method, script to send the request to, and a flag that determines whether the request is asynchronous.</p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;"><font color='Blue'>var</font> strURL = ‘postcode_lookup.php’;

xmlHttpReq.open(’POST’, strURL, <font color='Maroon'>true</font>);</pre>
<p>Finally we set the callback function displayPostcodethat will handle the script’s output.</p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;">xmlHttpReq.setRequestHeader(’Content-Type’, ‘application/x-www-form-urlencoded’);

xmlHttpReq.onreadystatechange = displayPostcode;</pre>
<p><strong>The Callback Function</strong></p>
<p>The callback function that we set in the previous section will be called whenever the state of the request has changed. When the request is completed, the <em>xmlHttpReq.readyState</em> will be set to 4.</p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;"><font color='Blue'>function</font> displayPostcode()
{
   document.getElementById(<font color='Maroon'>'outputDiv'</font>).innerHTML = <font color='Maroon'>""</font>;

   <font color='Blue'>var</font> postcodeData = <font color='Maroon'>""</font>;
   <font color='Blue'>var</font> output = <font color='Maroon'>""</font>;
   <font color='Blue'>if</font> (xmlHttpReq.readyState == <font color='Maroon'>4</font>)
   {
      postcodeData = xmlHttpReq.responseText.split(<font color='Maroon'>","</font>);

      output = <font color='Maroon'>""</font>;
      <font color='Green'>// processing information produced by the script</font>
      <font color='Blue'>if</font>( postcodeData.length &gt; <font color='Maroon'>1</font> )
      {
         output = <font color='Maroon'>"Postcode: "</font> + postcodeData[<font color='Maroon'>0</font>] + <font color='Maroon'>"&lt;br/&gt;"</font>;
         output += <font color='Maroon'>"Locality: "</font> + postcodeData[<font color='Maroon'>1</font>] + <font color='Maroon'>"&lt;/br&gt;"</font>;
         output += <font color='Maroon'>"State: "</font> + postcodeData[<font color='Maroon'>2</font>] + <font color='Maroon'>"&lt;br/&gt;"</font>;
         output += <font color='Maroon'>"Category: "</font> + postcodeData[<font color='Maroon'>9</font>] + <font color='Maroon'>"&lt;br/&gt;"</font>;
      }
      <font color='Blue'>else</font>
         output = <font color='Maroon'>"Postcode not found!"</font>;

      <font color='Green'>// writing output into div</font>
      document.getElementById(<font color='Maroon'>'outputDiv'</font>).innerHTML = "” + output + ““;
   }
   <font color='Blue'>else</font>
   {
      document.getElementById(<font color='Maroon'>'outputDiv'</font>).innerHTML = <font color='Maroon'>"loader.gif"</font>;
   }
}</pre>
<p>The callback function simply updates a div by looking at the information returned by the <em>xmlHttpReq.responseText</em>. While the request is not finished, we display a loading animated gif.</p>
<p><strong>The Request</strong></p>
<p>We have a <em>xmlHttpReq</em> object setup, and a callback function to handle the data returned by the script. Now we are ready to send the HTTP request to the script.</p>
<pre style="border:1px solid #cccccc;background-color:#f0f0ee;"><font color='Green'>// post to script</font>
xmlHttpReq.send(queryStr);</pre>
<p>&nbsp;</p>
<p>That&#8217;s it! We have a simple AJAX Postcode search. For this example the script is set to sleep for a couple of seconds, just so we can show off the loading gif :)</p>
<p>The zip file with the source code can be downloaded <a href="http://marcelzeng.com/blog/apps/postcodesearch/postcodesearch.zip">here</a>.</p>
<p>The loading gif was originally downloaded from <a href="http://www.ajaxload.info">here</a>, and the data with the postcode information was downloaded from the <a href="http://www.auspost.com.au">Australian Post</a> website.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/marcelpad.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/marcelpad.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/marcelpad.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/marcelpad.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/marcelpad.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/marcelpad.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/marcelpad.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/marcelpad.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/marcelpad.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/marcelpad.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/marcelpad.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/marcelpad.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/marcelpad.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/marcelpad.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/marcelpad.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/marcelpad.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=marcelpad.wordpress.com&amp;blog=2231039&amp;post=15&amp;subd=marcelpad&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://marcelpad.wordpress.com/2007/12/01/a-simple-ajax-example-searching-australian-postcodes/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Marcel</media:title>
		</media:content>
	</item>
	</channel>
</rss>
