<?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>Illuminati Karate, Inc. &#187; Javascript</title>
	<atom:link href="http://illuminatikarate.com/blog/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://illuminatikarate.com</link>
	<description>creative web design, development and marketing</description>
	<lastBuildDate>Wed, 16 May 2012 23:38:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Submitting a Contact Form via AJAX From Your Facebook Page</title>
		<link>http://illuminatikarate.com/blog/submitting-a-contact-form-via-ajax-from-your-facebook-page/</link>
		<comments>http://illuminatikarate.com/blog/submitting-a-contact-form-via-ajax-from-your-facebook-page/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 03:57:08 +0000</pubDate>
		<dc:creator>George Huger</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[FBJS]]></category>
		<category><![CDATA[FBML]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/blog/?p=297</guid>
		<description><![CDATA[Note: this post over over 2 years old and may need modifications. We recently created a contact submission form on a client&#8217;s Facebook page, and were not satisfied with the default user experience. For starters, the form opened a new window, and there was no way to redirect the [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><em>Note: this post over over 2 years old and may need modifications.</em></p>
<p>We recently created a contact submission form on a client&#8217;s Facebook page, and were not satisfied with the default user experience. For starters, the form opened a new window, and there was no way to redirect the user back to a confirmation message on the Facebook page. </p>
<p>We decided to submit the form via AJAX instead, and show the confirmation message directly on the Facebook page. This way the user would not have to leave the Facebook page, resulting in a smoother user experience. We couldn&#8217;t find a good explanation of how to do this on Google, so after figuring it out I decided to go ahead and write it up. </p>
<p>The following example will show you how to submit a basic contact form using AJAX from within your Facebook page. All HTML and Javascript that follows should be pasted directly into the &#8220;Edit FBML&#8221; screen on Facebook.</p>
<p><span id="more-297"></span>Here&#8217;s the example form HTML we&#8217;ll use for the rest of this article. It&#8217;s just two text fields (name and email) and a submit button:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p297code4'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2974"><td class="code" id="p297code4"><pre class="html" style="font-family:monospace;">&lt;form action=&quot;http://mywebsite.com/form_submit.php&quot; method=&quot;post&quot;&gt;
     &lt;p&gt;
          &lt;label for=&quot;name&quot;&gt;Name:&lt;/label&gt;
          &lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;name&quot; /&gt;
     &lt;/p&gt;
     &lt;p&gt;
          &lt;label for=&quot;email&quot;&gt;Email:&lt;/label&gt;
          &lt;input type=&quot;text&quot; name=&quot;email&quot; id=&quot;email&quot; /&gt;
     &lt;/p&gt;
     &lt;button type=&quot;submit&quot; onclick=&quot;return submitAjaxForm();&quot;&gt;Submit&lt;/button&gt;
     &lt;p id=&quot;ajaxMessage&quot;&gt;&lt;/p&gt;
&lt;/form&gt;</pre></td></tr></table></div>

<p>There&#8217;s three things you should take note of:</p>
<ol>
<li>The form&#8217;s <b>action</b> attribute is set to a page on mywebsite.com, not facebook.com (replace mywebsite.com with your own domain)</li>
<li>The submit button has an onSubmit event that calls a function submitAjaxForm, which we&#8217;ll define shortly</li>
<li>At the end of the form is an empty paragraph tag. We&#8217;ll use this space to display messages to the user.</li>
</ol>
<p>On our server, form_submit.php is a simple PHP script that logs the submissions, and sends back a message for the user letting them know the submission was successful. It might look something like this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p297code5'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2975"><td class="code" id="p297code5"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
     log_submission<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Thank you for your submission!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Of course, your script will be more sophisticated than this one, and doesn&#8217;t have to be written in PHP. Its on your server, so you can handle logging the submission however you like. Just make sure the output is valid <a href="http://wiki.developers.facebook.com/index.php/FBML">FBML</a>.</p>
<p>With the form HTML added to your Facebook page and the logging script in place, the only thing left is adding the Javascript to submit the form via AJAX and show the confirmation message.</p>
<p class="note"><b>Note:</b> Facebook does not allow you to use any Javascript function you like, for security purposes. Instead they&#8217;ve created a library of Javascript functions for accessing the DOM, AJAX, and event binding called <a href="http://wiki.developers.facebook.com/index.php/FBJS">FBJS</a>. These functions are used in the example below.</p>
<p>We&#8217;ll now define the submitAjaxForm() function we referenced earlier in our submit button&#8217;s onSubmit event:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p297code6'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2976"><td class="code" id="p297code6"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;&lt;!--</span>
<span style="color: #003366; font-weight: bold;">function</span> submitAjaxForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span> 
	<span style="color: #006600; font-style: italic;">// declare a new FBJS AJAX object</span>
	<span style="color: #003366; font-weight: bold;">var</span> ajax <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ajax<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	ajax.<span style="color: #660066;">responseType</span> <span style="color: #339933;">=</span> Ajax.<span style="color: #660066;">FBML</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// define a callback to handle the response from the server</span>
	ajax.<span style="color: #660066;">ondone</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span> 
		document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ajaxMessage'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setInnerFBML</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// let the user know we're sending the data	</span>
	document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ajaxMessage'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setInnerXHTML</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Submitting your information, please wait...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// collect field values</span>
	<span style="color: #003366; font-weight: bold;">var</span> queryParams <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">'name'</span> <span style="color: #339933;">:</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'email'</span> <span style="color: #339933;">:</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'email'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	ajax.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'http://mywebsite.com/form_submit.php'</span><span style="color: #339933;">,</span> queryParams<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #006600; font-style: italic;">//--&gt;&lt;/script&gt;</span></pre></td></tr></table></div>

<p><em>Note: The opening and closing HTML comments embedded in the Javascript are important, so leave them intact.</em></p>
<p>The example is fairly self explanatory, but here&#8217;s what&#8217;s happening:</p>
<ol>
<li>Declare a new Ajax object, which is one of the FBJS classes. We then set its response type to FBML (Ajax.RAW and Ajax.JSON are also accepted).</li>
<li>Define a callback function to handle the response from the server. In this case, our function simply takes the response from the server and displays it in the #ajaxMessage paragraph we defined earlier.</li>
<li>Update the user to let them know their data is being submitted using FBJS&#8217;s setInnerFBML function.</li>
<li>Collect the form field&#8217;s values into an array named queryParams, using FBJS&#8217;s getElementById and getValue functions. Although getElementById is similar to the standard Javascript function, it accounts for the random slugs Facebook injects into div id&#8217;s for security (View Source on a Facebook page and look at the div ID&#8217;s to see this in action).</li>
<li>Send the AJAX request, using FBJS&#8217; Ajax.post function. The second argument is optional, and should be an array containing the query parameters.</li>
<li>&#8220;return false;&#8221; prevents the form&#8217;s normal submit behavior</li>
</ol>
<p>That&#8217;s all there is to it! If you have any questions or if I should clarify a section, let me know in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/submitting-a-contact-form-via-ajax-from-your-facebook-page/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>Write Your Own jQuery Selectors</title>
		<link>http://illuminatikarate.com/blog/write-your-own-jquery-selectors/</link>
		<comments>http://illuminatikarate.com/blog/write-your-own-jquery-selectors/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 16:14:29 +0000</pubDate>
		<dc:creator>George Huger</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[custom selectors]]></category>
		<category><![CDATA[extend jquery]]></category>
		<category><![CDATA[selectors]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/blog/?p=69</guid>
		<description><![CDATA[jQuery has a powerful collection of selectors which make selecting a specific collection of elements much simpler. Among my favorites are :text, which matches one-line text inputs, and :checked, for determining what checkboxes in a group have been selected. But sometimes our filter criteria relies on domain specific information. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jquery.com">jQuery</a> has a powerful collection of selectors which make selecting a specific collection of elements much simpler. Among my favorites are :text, which matches one-line text inputs, and :checked, for determining what checkboxes in a group have been selected. But sometimes our filter criteria relies on domain specific information. </p>
<p><span id="more-372"></span>Take for example an alumni foundation seeking to target all alumni who donated at least $1,000 last year. Their donor database provides them a table of alumni showing their 2008 donations, like this:</p>
<p><a href="http://illuminatikarate.com/wp-content/uploads/2009/03/sample_donor_table.png"><img class="aligncenter size-full wp-image-70" title="Sample Data Table: Alumni Donors" src="http://illuminatikarate.com/wp-content/uploads/2009/03/sample_donor_table.png" alt="Sample Data Table: Alumni Donors" width="290" height="136" /></a></p>
<p>It would be great if we could select these rows easily in jQuery. From there we could remove the others who donated less than $1k from the list, or highlight the ones who did. Ideally, we&#8217;d like to do something like this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p372code10'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p37210"><td class="code" id="p372code10"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tr:bigdonor'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'highlight'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Of course, &#8220;bigdonor&#8221; isn&#8217;t a real selector, but jQuery makes it trivial to change that. All we must do is define the bigdonor selector, and provide an expression which returns true if the given object is a match, and false if not. Here&#8217;s the code:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p372code11'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p37211"><td class="code" id="p372code11"><pre class="javascript" style="font-family:monospace;">jQuery.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>
	jQuery.<span style="color: #660066;">expr</span><span style="color: #009900;">&#91;</span> <span style="color: #3366CC;">&quot;:&quot;</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#123;</span>
		bigdonor <span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;parseInt(jQuery(a).find('td:last').html()) &gt;= 1000&quot;</span> <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Explanation:</p>
<p>The first line starts a call to jQuery.extend(), which is a function that allows us to add functionality to jQuery and is the basic way we implement plugins. In the case of a plugin we would extend the jQuery object itself, but in this case we want to extend jQuery&#8217;s &#8220;:&#8221; expression. </p>
<p>Line 4 is where we actually define our custom selector. jQuery already has a <a href="http://docs.jquery.com/Selectors">list of predefined selectors</a> just like this, and we&#8217;re just adding another to the list. Selectors come in two parts, separated by a colon: a symbol, and an expression which must evaluate to true or false. In our case &#8220;bigdonor&#8221; is the symbol, and the expression is the code in quotes. There&#8217;s a bit going on there that&#8217;s worth explaining:</p>
<p>In the context of selectors, <em>a</em> is an object which represents the current element. Its equivalent to <em>this</em> in other contexts. So this code looks for the last td element contained by the current element, converts its inner HTML into an integer, and then returns whether or not the result is at least 1000.</p>
<p>With our new selector defined, our original code works as intended. Here it is again:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p372code12'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p37212"><td class="code" id="p372code12"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tr:bigdonor'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'highlight'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The resulting table might look something like this:</p>
<p><a href="http://illuminatikarate.com/wp-content/uploads/2009/03/sample_donor_table_highlighted.png"><img src="http://illuminatikarate.com/wp-content/uploads/2009/03/sample_donor_table_highlighted.png" alt="Sample data table after highlighting" title="Sample data table after highlighting" width="290" height="136" class="aligncenter size-full wp-image-78" /></a></p>
<p>Thats it! Our example is fairly basic, but hopefully you&#8217;ve already thought of some ways this can come in handy for your own projects. We find them especially useful for enhancing legacy <a href="http://illuminatikarate.com/web-services/web-development/">web apps</a> without modifying the underlying codebase.</p>
]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/write-your-own-jquery-selectors/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Relative Offsets Are Handled Differently Between Versions of jQuery</title>
		<link>http://illuminatikarate.com/blog/relative-offsets-are-handled-differently-between-versions-of-jquery/</link>
		<comments>http://illuminatikarate.com/blog/relative-offsets-are-handled-differently-between-versions-of-jquery/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 20:51:34 +0000</pubDate>
		<dc:creator>George Huger</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[animate]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/blog/?p=58</guid>
		<description><![CDATA[This post highlights a difference between jQuery 1.2 and later in how relative values are handled, which I recently discovered when upgrading a site from jQuery 1.2 to the new 1.3. If you&#8217;re about to do the same, or have recently broken your site after upgrading and don&#8217;t know [...]]]></description>
			<content:encoded><![CDATA[<p><em>This post highlights a difference between jQuery 1.2 and later in how relative values are handled, which I recently discovered when upgrading a site from jQuery 1.2 to the new 1.3. If you&#8217;re about to do the same, or have recently broken your site after upgrading and don&#8217;t know why, this post is for you. It will be easier to explain with an example, so here&#8217;s how the problem manifested for us:</em></p>
<p>On our old website we used jQuery to slide the pages into view when a user clicks on a navigation link. This is a variation of the &#8220;Coda Slider&#8221;, named because it mimics the website for Panic software&#8217;s <a href="http://www.panic.com/coda/">Coda</a> editor. In a nutshell, we have a div which acts as a viewport (we&#8217;ll call it #viewport), with another div inside which contains the pages (which we&#8217;ll call #slideContainer). #viewport has its position property set to relative, and its child, #slideContainer, has its position set to absolute. So when we increase or decrease the value of #slideContainer&#8217;s left property, it will slide right or left respectively to reveal new pages. Here&#8217;s an example:</p>
<p><span id="more-371"></span><a href="http://illuminatikarate.com/wp-content/uploads/2009/03/fig1-coda-slider-setup.png"><img class="aligncenter size-full wp-image-59" title="Figure 1: Div layout for a &quot;Coda Slider&quot;" src="http://illuminatikarate.com/wp-content/uploads/2009/03/fig1-coda-slider-setup.png" alt="Figure 1: Div layout for a &quot;Coda Slider&quot;" width="501" height="700" /></a></p>
<p>If the width of one page is 800px, then setting the inner div&#8217;s left property to 0 will show the first page, and setting the left property to -800px will bring the second page into view. -1600px shows the third page, -2400px shows the fourth, and so on. So all we have to do is adjust the left property of that div when we want to change what pages is shown, which we would do using <a href="http://docs.jquery.com/Effects/animate">jQuery&#8217;s animate function</a>. Such a call might look like this:<br />
<code>$('#slideContainer').animate({left: -800px});</code><br />
This works as you would expect when the starting left value is 0 &#8211; #slideContainer will end with a value of -800px. The problem arises when we try to adjust the left value when its not starting at 0. For instance, if we were looking at the second page, #slideContainer would have a left value of -800px and the second page would be shown. If we then wanted to move to the third page, meaning left needs a value of -1600px, we would expect this to work:<br />
<code>$('#slideContainer').animate({left: -1600px});</code></p>
<p>In jQuery 1.2.1 or later this will work as you would expect, namely #slideContainer&#8217;s left is set to -1600px. However, in jQuery 1.2 values beginning with + or &#8211; are interpreted as relative values, which means that animate call would be interpreted as &#8220;subtract 1600px from the left of #slideContainer.&#8221; If left started at -800px, it would end at -2400px instead of -1600px as we intended.</p>
<p>To workaround this, our code was calculating how much the div needed to move relative to its current position and passing that value to the animate function instead. When we upgraded jQuery, this resulted in the pages sliding to arbitrary positions. To fix it, we stopped calculating the relative movement needed and simply pass the desired left value.</p>
<p class="note">Note: you can still use relative offsets in new versions jQuery. Just use += and -= instead.</p>
<p>For the advanced readers, this bug was identified as <a href="http://dev.jquery.com/ticket/1607">ticket #1607</a>, and fixed in <a href="http://dev.jquery.com/changeset/3299">changeset 3299</a> by <a href="http://ejohn.org">John Resig</a>.</p>
<p>This is one of many small bug fixes between versions of jQuery that have caused us to dig back through old code. I&#8217;ll be posting more as we find them. The takeaway for me is that you should always include a specific version of jQuery (don&#8217;t ever include jquery-latest.js from Google Code) and make sure to test thoroughly whenever you&#8217;re upgrading to a new version of jQuery.</p>
]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/relative-offsets-are-handled-differently-between-versions-of-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>10 Javascript Tricks for Better Forms</title>
		<link>http://illuminatikarate.com/blog/10-javascript-tricks-for-better-forms/</link>
		<comments>http://illuminatikarate.com/blog/10-javascript-tricks-for-better-forms/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 17:53:56 +0000</pubDate>
		<dc:creator>George Huger</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[combo box]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[progress bars]]></category>

		<guid isPermaLink="false">http://illuminatikarate.com/blog/?p=4</guid>
		<description><![CDATA[Nothing exposes the gap between web apps and desktop applications more than plain HTML forms. Fortunately, by leveraging Javascript we can start to close this gap while maintaining a consistent experience for users using screen readers and old browsers. We&#8217;ve identified 10 ways in which normal HTML forms fall [...]]]></description>
			<content:encoded><![CDATA[<p>Nothing exposes the gap between web apps and desktop applications more than plain HTML forms. Fortunately, by leveraging Javascript we can start to close this gap while maintaining a consistent experience for users using screen readers and old browsers.</p>
<p>We&#8217;ve identified 10 ways in which normal HTML forms fall short, and dug up the Javascript and CSS code you&#8217;ll need to fix them. Although the best enhancements are so intuitive as to be unnoticed, rest assured your visitors would thank you if they knew.</p>
<p class="note"><em>Note: Many of the solutions in this list depend on <a href="http://jquery.com">jQuery</a>, our javascript framework of choice.</em></p>
<p><span id="more-369"></span></p>
<h4>Combo Boxes</h4>
<p>For those unfamiliar, a Combo Box is a combination of a text box and a list box. It allows the user the option of selecting from a list of predefined items, or entering a new item of their choice. Your browser&#8217;s address bar is a perfect example.</p>
<p>Its an elegant solution to a common problem, yet the combo box was somehow left out of HTML&#8217;s form elements.</p>
<p>Enter <strong><a href="http://code.google.com/p/sexy-combo/">Sexy Combo</a></strong>, a jQuery plugin which provides a seamless solution. Users without javascript will simply encounter a normal select element.</p>
<h4>Progress Bars For Uploads</h4>
<p>The standard file input frustrates users with its awkwardness and lack of information. Furthermore, not being able to upload asynchronously results in a lot of wasted time.</p>
<p>To be fair, providing information on an ongoing upload is trickier than it might sound. Thankfully, <strong><a href="http://swfupload.org">SWFUpload</a></strong> provides a very clean solution that will convert your standard file inputs into a very flexible and asynchronous file uploader complete with a progress bar.</p>
<p class="note"><em>Note: As the name implies, SWFUpload uses an invisible Flash movie to actually perform the upload. As such, your users will need Flash as well as javascript enabled to take advantage.</em></p>
<h4>Date Selection</h4>
<p>Using a standard text input for a date leads to all manner of formatting issues, and using 3 select boxes is cumbersome. Desktop apps have a great solution &#8211; the date picker, which is to say a pop-up calendar.</p>
<p><a href="http://ui.jquery.com/demos/datepicker"><strong>jQuery UI&#8217;s Datepicker plugin</strong></a> is a perfect solution.</p>
<p class="note"><em>Note: The download page is for the entire jQuery UI library, but will allow you to download only what you want. I&#8217;d recommend only downloading the Datepicker with Packed compression, as the library is quite large.</em></p>
<h4>Time Selection</h4>
<p>Time selection in a normal HTML form has the same problems as date selection, but it lacks a uniform solution. We&#8217;ve provided 2 implementations, so that you can decide which is more appropriate for your audience.</p>
<p><strong><a href="http://keith-wood.name/timeEntry.html">Time Entry</a></strong> is a jQuery plugin that is simple and very customizable. Its normal behavior is to provide a text box where the user can use the arrow keys to quickly set the hour, minute, and am/pm settings. Its similar to how you set the time in Windows, so it should be intuitive for most visitors.</p>
<p><a href="http://www.oakcitygraphics.com/jquery/clockpick/trunk/ClockPick.cfm"><strong>ClockPick</strong></a> is a more creative, but less traditional solution. If you&#8217;re generally comfortable with creative inputs, its a fantastic interface.</p>
<h4>Color Selection</h4>
<p>Color selection might not apply to every app, but when you need it the native options leave you out in the cold. There&#8217;s only a handful of visitors who would know what a hex code is, and even fewer who have their favorites memorized.</p>
<p><a href="http://www.eyecon.ro/colorpicker/"><strong>ColorPicker</strong></a> is a very nice solution, which provides a color picker similar to that in Adobe Photoshop.</p>
<h4>Input Masking / Validation</h4>
<p>Input masking is when a text box has static characters already included, and the cursor moves intelligently. For example, a text box for a social security number should already have the dashes, and after you enter the first three numbers the cursor should move past the first dash. Furthermore, it shouldn&#8217;t allow anything but numbers to be entered.</p>
<p>Input validation is checking to see if the value the user entered falls within the boundaries. In our social security number example, if the number entered isn&#8217;t exactly 9 digits, its not valid.</p>
<p class="note"><em>Note: Client-side validation can be easily overridden by a malicious visitor, so you&#8217;ll need to sanitize and validate your data server-side as well.</em></p>
<p>The <strong><a href="http://digitalbush.com/projects/masked-input-plugin/">Masked Input jQuery plugin</a></strong> can implement both of these features for us. It will let you define any custom mask, and you can use its &#8220;completed&#8221; callback function to flag the inputs as valid.</p>
<h4>Better Support for Defaults</h4>
<p>HTML inputs do allow for default values, but its nice to have them disappear when the input gains focus, and reappear on blur if the user hasn&#8217;t entered anything.</p>
<p>The aptly named <strong><a href="http://plugins.jquery.com/project/defaultvalue">Default Values plugin</a></strong> does exactly that.</p>
<h4>AJAX Form Submission</h4>
<p>Submitting forms can be a great use of AJAX, particularly if you have a series of forms which are affected by the user entered values (i.e. a wizard). Its also a nice way to break a long form into stages to decrease abandonment.</p>
<p>The <strong><a href="http://malsup.com/jquery/form/">jQuery Form Plugin</a></strong> is an easy way to convert your current forms to AJAX forms while preserving their functionality for users without Javascript. If you are feeling creative or want to write something more customized, <strong><a href="http://docs.jquery.com/Ajax/serialize">jQuery&#8217;s serialize function</a></strong> will get you almost all the way there.</p>
<h4>Automatically Growing Textareas</h4>
<p>If you&#8217;ve used <a href="http://facebook.com">Facebook</a> or <a href="http://basecamphq.com">Basecamp</a>, you&#8217;ve probably noticed that the textareas get longer when you&#8217;re running out of space. Its aesthetically pleasing and very convenient.</p>
<p>Here&#8217;s a <a href="http://plugins.jquery.com/project/autogrow"><strong>jQuery plugin</strong></a> to add the same behavior to your textareas.</p>
<h4>Spin Buttons</h4>
<p>A spin button is a text box with up/down arrows, allowing the user to easily &#8220;nudge&#8221; a numeric value up or down. Like a combo box, the user can still type in their own value.</p>
<p>They are most useful when the range of possible values is fairly small &#8211; for example selecting the number of diners in a reservation.</p>
<p>The <strong><a href="http://code.google.com/p/jquery-spin-button/">jQuery Spin Button</a></strong> plugin is a nice implementation of this control.</p>
<h4>One More Thing</h4>
<p>Each of these ten solutions requires at least one external javascript library, and some require stylesheets. Implementing all ten would be great, but including a bunch of external javascript / css files can drastically increase the load time of your page.</p>
<p>Therefore, we recommend you do 2 things:</p>
<ol>
<li>Concatenate your Javascript and CSS files as much as makes sense.</li>
<li>Compress them using Dean Edward&#8217;s <a href="http://dean.edwards.name/packer/">packer</a> and <a href="http://www.cssdrive.com/index.php/main/csscompressor/">CSSDrive&#8217;s CSS Compressor</a>, respectively.</li>
</ol>
<p>Also, if you know of any scripts that we missed here let us know in the comments. Thanks for reading!</p>
]]></content:encoded>
			<wfw:commentRss>http://illuminatikarate.com/blog/10-javascript-tricks-for-better-forms/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

