<?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>my crazy blog &#187; Javascript is Your Friend</title>
	<atom:link href="http://mycrazydream.net/wp/category/javascript-is-your-friend/feed/" rel="self" type="application/rss+xml" />
	<link>http://mycrazydream.net/wp</link>
	<description>c o d e  p o e t r y  a n d  h i g h  c r a z i n e s s</description>
	<lastBuildDate>Fri, 20 Jan 2012 07:01:19 +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>Websites on the Frontier</title>
		<link>http://mycrazydream.net/wp/2010/03/starting-a-website-on-the-frontier/</link>
		<comments>http://mycrazydream.net/wp/2010/03/starting-a-website-on-the-frontier/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 02:30:23 +0000</pubDate>
		<dc:creator>mcd</dc:creator>
				<category><![CDATA[Javascript is Your Friend]]></category>
		<category><![CDATA[My Crazy Dream]]></category>
		<category><![CDATA[browser wars]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[functionality]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[social media]]></category>
		<category><![CDATA[web dev]]></category>

		<guid isPermaLink="false">http://mycrazydream.net/wp/?p=447</guid>
		<description><![CDATA[Just what does it take to create a website that looks great but that will attract users?]]></description>
			<content:encoded><![CDATA[<style>
.withlogo{padding-top:38px !important;font-size:15px !improtant;background-position:bottom right;background-repeat:no-repeat;}
.facebook{background-image:url(/wp/wp-content/uploads/2010/03/facebook-logo16k.jpg);}
.igoogle{background-image:url(/wp/wp-content/uploads/2010/03/igoogle.png);}
.netflix{background-image:url(/wp/wp-content/uploads/2010/03/netflix_logo.gif);}
.mozilladev{background-image:url(/wp/wp-content/uploads/2010/03/mdc-logo.png);}
.pandora{background-image:url(/wp/wp-content/uploads/2010/03/PandoraLogo-small.jpg);}
</style>
<p><script>
jQuery(document).ready(function($){jQuery('#post-447 h2:first-child').css({'background':'transparent url(/wp/wp-content/uploads/2010/03/webdesign.jpg) bottom right no-repeat','padding-top':'80px'});});
</script></p>
<p>
If I hear the <acronym title="World Wide Web">WWW</acronym> being compared to the Wild West one more time, I&#8217;m gonna have the urge to punch a baby (there aren&#8217;t any babies in the audience, are there?). Sure, the modern web is a wild and crazy place.  Now, frankly, I think this is awesome, but it begs the question. How does a reputable company or service provider make a name for themselves in such a lawless world?</p>
<p>You can be sure that no matter how much time you spend developing the perfect site, following every rule in the book of <acronym title="Search Engine Optimization">SEO</acronym> and standards compliance, rest assured, someone will either be doing it better, or soon will be. For the vast majority of the web (forget about eBay for a second, such a behemoth is the exception) you succeed by doing one or two things, and doing them extremely well. This focus is best split into two areas.
</p>
<h2>The First Focus</h2>
<p>First, of course, is the &#8220;what&#8221; of your website. What does your website offer? Why is it even on the web?</p>
<h2>The Second Focus</h2>
<p>Second, is the design and functionality of your site. Something within this vast world of possibilities must stand out. If you have a great idea and fail here, the web might not be the arena for you.</p>
<p>
If you&#8217;re lucky, you can get by focusing on one or the other, but who wants to bet on luck to succeed? An example site with such a singular focus would be <a title="Visit Craigslist" target="_blank" href="http://www.craigslist.org/about/sites">Craigslist</a>. Craigslist has zero design going for it. Functionality? Forget about it; the site could be transported back five, maybe ten years and still function exactly the same. Besides simplicity, Craigslist is awesome because it provides a service that everyone needs, and yes, it&#8217;s free. But forget about them. The following is a list of sites that are doing it right on both fronts.
</p>
<h2>The Shining Examples</h2>
<h3 class="withlogo netflix">Netflix</h3>
<p>
The first site that came to mind when I sat down to write this post was <a title="Visit Netflix" target="_blank" href="http://www.netflix.com">Netflix</a>. Sure, providing movies through the mail is a fantastic idea, Netflix came to the table with a stacked deck, but they didn&#8217;t stop there. Netflix realized that people love to watch movies, but they don&#8217;t always know just <em>which</em> movies to watch. The problem Netflix faced was how to provide their users with the movies that they love. But just how is a website supposed to know that? Based on your previous rankings of films you&#8217;ve seen, Netflix utilizes a sophisticated algorithm to deliver just that. And they are constantly improving it. Or, with the <a title="Enter contest. Win money." target="_blank" href="http://www.netflixprize.com/">Netflix Prize</a>, they&#8217;ve come up with an innovative way to not just have a great algorithm, but to have the best.
</p>
<p>
And talk about great design. The interface is clean and intuitive (if you don&#8217;t have a membership, you&#8217;re going to miss most everything unfortunately). Everything is just where you expect it to be to the point that the interface becomes unnoticed, just as a good user interface should be. It gets you to where you want to be.
</p>
<h3 class="withlogo facebook">Facebook</h3>
<p>
I have to mention the website that is popular enough these days to induce groans just by being mentioned. (That&#8217;s when you know you&#8217;ve really made it. Pissing off hipsters.) In almost no time, <a title="Visit the MySpace Killer" target="_blank" href="http://www.facebook.com">Facebook</a> can connect you with just about everyone you&#8217;ve ever know in your life. That&#8217;s a small exaggeration, but not by much.
</p>
<p>
What I really admire about Facebook, as a front-end developer myself, is just how well they use JavaScript to enhance the user experience, with modal windows that appear when necessary, and just as quickly fade to get out of your way. Their library is fast, and they&#8217;ve designed it in the right way so it plays nice with the outside world, meaning, it doesn&#8217;t take much for outside developer&#8217;s to integrate their own work.
</p>
<h3 class="withlogo igoogle">iGoogle</h3>
<p>
<a title="iWhat? How very iApple of you, Google" target="_blank" href="http://www.google.com/ig">iGoogle</a> has been my start page of choice for some time now. It is more than just a portal. At any time I can open up my browser, quickly scan iGoogle, and have an accurate, if summary, picture of all that is going on in the web. At least, the parts that I care about. iGoogle is fully customizable down to the overall theme you choose to display your widgets in. Mix and match which widgets you want to show, and then customize each one of those to fit you perfectly.
</p>
<p>Service? Check. Functionality? Forget about it. Design? Your choice. It looks as good as you want it to, with just a couple clicks. I don&#8217;t want to give too much away, I want you to go and play with it. You&#8217;ll never turn back.</p>
<h3 class="withlogo mozilladev">Mozilla Dev</h3>
<p>
There are countless technical resources for the developer, some of which are much more exhaustive than <a title="Go ahead, educate yourself" target="_blank" href="https://developer.mozilla.org/">Mozilla Dev</a>. But really, who wants to wade through all that when one is looking for a quick answer and needs to get back to work? It is the combination of both the service and the design of the site that makes it such a success. As a developer, I can find the JavaScript reference I am looking for, load up the page, and find the answer I need without barely even reading. A quick scan will do it. Compare this to <acronym title="Microsoft Developer Network">MSDN</acronym>.
</p>
<p>
Here is a common JavaScript function for a popup, <em>window.open</em>. Let&#8217;s compare the two reference sites. Here is <a title="window.open" target="_blank" href="https://developer.mozilla.org/En/DOM/Window.open">Mozilla Dev</a> and here is <a title="window.suck()" target="_blank" href="http://msdn.microsoft.com/en-us/library/ms536651%28VS.85%29.aspx">MSDN</a>. The clean separation on Mozilla, combined with clear headers, allows the reader to find answers right away. You have to pore over material on <a title="The Pits of Despair!" target="_blank" href="http://msdn.microsoft.com/">MSDN</a>, deciphering tiny italics in a serif font (code in a serif font?? really??). Oh, and just as the final nail in the casket, Mozilla has real world examples and a beautiful graphic that clearly describes what each parameter does. This all comes as no surprise for anyone who&#8217;s ever tried to debug code in <a title="Die IE, Die!" target="_blank" href="http://www.ie6nomore.com">Internet Explorer</a>. Microsoft would rather JavaScript remained some arcane secret, and will only taunt you with cryptic error messages if your code breaks.
</p>
<h2>One Less-than-Stellar Example</h2>
<h3 class="withlogo pandora">Pandora</h3>
<p>
I can hear you screaming already. &#8220;What?! <a title="Musical suggestions for the aurally challenged" target="_blank" href="http://www.pandora.com">Pandora</a> is awesome!&#8221; I know, I love it too. It has the first focus down perfectly. However, in the long run I think Pandora will come up short against rival services like <a title="Pandora's Rival" target="_blank" href="http://www.last.fm/">last.fm</a>, and others, fast emerging. First of all, I am generally not a fan of a Flash website. It&#8217;s a great format for playing movies in, and many designer&#8217;s websites look gorgeous in Flash, but for utility it is sorely lacking.
</p>
<p>Don&#8217;t expect your scroll-wheel to work. Want to tab to the next input field? I don&#8217;t think so. And if we look under the hood we get to read some strange code.</p>
<caption>Thank god we still have this function.</caption>
<p><code><br />
function setPromotionalTickerLink(url) {<br />
	// do nothing. (but we're leaving this function here because legacy ads call it.)<br />
}<br />
</code></p>
<caption>What, you don&#8217;t have access to your server config? We&#8217;re doing this client side?</caption>
<p><code><br />
// jh.9.28.2009 - redirect homepage requests from host "pandora.com" to "www.pandora.com"<br />
    // required for js->tuner communication, which presently expects same host (down to the subdomain)<br />
    if (document.location.href.indexOf("//pandora.com") != -1) {<br />
        document.location.href = document.location.href.replace(/\/\/pandora.com/, "//www.pandora.com");<br />
    }<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://mycrazydream.net/wp/2010/03/starting-a-website-on-the-frontier/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Save an HTML Form With AJAX</title>
		<link>http://mycrazydream.net/wp/2008/12/save-an-html-form-with-ajax/</link>
		<comments>http://mycrazydream.net/wp/2008/12/save-an-html-form-with-ajax/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 18:30:40 +0000</pubDate>
		<dc:creator>mcd</dc:creator>
				<category><![CDATA[Javascript is Your Friend]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://mycrazydream.net/?p=6</guid>
		<description><![CDATA[If you&#8217;re reading this then you already have some experience with that wonderful little aspect of javascript that allows you, the developer, to deliver content to your users without reloading an entire page in the browser. If you think that AJAX is just some Greek warrior (you literary nerd, you) first head here to start [...]]]></description>
			<content:encoded><![CDATA[<p>
If you&#8217;re reading this then you already have some experience with that wonderful little aspect of javascript that allows you, the developer, to deliver content to your users without reloading an entire page in the browser. If you think that AJAX is just some Greek warrior (you literary nerd, you) first <a href="http://www.w3schools.com/Ajax/Default.Asp">head here</a> to start using what has already become damn near ubiquitous on the web. The rest, please read on.
</p>
<p>
So you already know how to send/receive data with javascript do you? Good. Let&#8217;s beef those javascript skills up even further then. The catch, as it were, to saving data from an HTML form, is in treating each type of HTML element differently. Or rather, to realize that they all behave differently and that you&#8217;re going to have to build your javascript to treat them differently to. In short, make it play nice-like with the other kiddies.
</p>
<p>
Plain vanilla text inputs are easy enough.
</p>
<pre class="brush: javascript">
getValue = document.form.inputName.value;
</pre>
<p>or</p>
<pre class="brush: javascript">
getValue = document.getElementById(&#039;inputID&#039;).value;
</pre>
<p>
But how do we handle checkboxes? What about the <i>select</i> element? First, let&#8217;s assume that we do only have plain text inputs in our form. Unlikely in the real world, but it will give us a base function, which makes use of the super awesome built in js function, getElementsByTagName. It should be noted that this always returns an array of HTML elements.
</p>
<pre class="brush: javascript">
/*
form here is the HTML form object
An easy way to pass this from your page to the function:
&lt;form name=&quot;formName&quot; onsubmit=&quot;saveForm(this);&quot;&gt;
*/
function saveForm(form)
{
  // key is the primary key in the db
  // this would most likely be a hidden input in your form
  // I use it as a base to start building the query string
  // we want to create something that looks like
  // ?key=keyValue&amp;input1=value1&amp;input2=value2
  var q = (form.key ? &#039;?key=&#039;+form.key.value : &#039;?key=&#039;);

  var els = form.getElementsByTagName(&#039;input&#039;);

  //parse input elements
  for(var i=0;i&lt;els.length;i++)
  {
      // for those familiar with php, escape is similar to urlencode
      // we need our data safe to pass in a url
      q += &#039;&amp;&#039; + els[i].name + &#039;=&#039; + escape(els[i].value);
  }
}
</pre>
<p>
This core function forms the basis for the rest of the exercise. We just need to work on &#8216;playing nice&#8217; with the other elements. For the <i>checkbox</i>:
</p>
<pre class="brush: javascript">
for(var i=0;i&lt;els.length;i++)
  {
    if(els[i].type==&#039;checkbox&#039;)
    {
      // I usually give my checkboxes values of 1 or 0
      // so we just check if it is checked, and pass
      // the value accordingly
      q += &#039;&amp;&#039; + els[i].name + &#039;=&#039; + //--&gt;
        (els[i].checked==true ? els[i].value : &#039;0&#039;);
    }
    else
    {
      q += &#039;&amp;&#039; + els[i].name + &#039;=&#039; + escape(els[i].value);
    }
  }
</pre>
<p>
And the <i>select</i> element. The important thing to note about the select element is that we really don&#8217;t care about its values at all. It doesn&#8217;t even have any! OK, so you can often get away with grabbing the value from it, but what we are really doing is getting the values from its children; the <i>option</i> elements:
</p>
<pre class="brush: javascript">
var sels = form.getElementsByTagName(&#039;select&#039;);

for(var i=0;i&lt;sels.length;i++)
  {
    q += &#039;&amp;&#039; + sels[i].name + &#039;=&#039;
    for (var j=0; j&lt;sels[i].options.length; j++)
    {
      if (sels[i].options[j].selected)
      {
        q += escape(sels[i].options[j].value)+&#039;,&#039;;
      }
    }
  }
</pre>
<p>
OK, so learning time is over. If you are in a hurry like most developers and just scrolled down to the finished product, here you go. The whole function is here, with <i>textarea</i> thrown in to boot, free of charge.
</p>
<pre class="brush: javascript">
function saveForm(form)
{
  // key is the primary key in the db
  // this would most likely be a hidden input in your form
  var q = (form.key ? &#039;?key=&#039;+form.key.value : &#039;?key=&#039;);

  var els = form.getElementsByTagName(&#039;input&#039;);

  //parse input elements
  for(var i=0;i&lt;els.length;i++)
  {
    if(els[i].type==&#039;checkbox&#039;)
    {
      q += &#039;&amp;&#039; + els[i].name + &#039;=&#039; + //--&gt;
        (els[i].checked==true ? els[i].value : &#039;0&#039;);
    }
    else
    {
      q += &#039;&amp;&#039; + els[i].name + &#039;=&#039; + escape(els[i].value);
    }
  }

  //parse textarea elements
  var tels = form.getElementsByTagName(&#039;textarea&#039;);

  for(var i=0;i&lt;tels.length;i++)
  {
    q += &#039;&amp;&#039; + tels[i].name + &#039;=&#039; + escape(tels[i].value);
  }

  // parse select elements
  var sels = form.getElementsByTagName(&#039;select&#039;); 

  for(var i=0;i&lt;sels.length;i++)
  {
    q += &#039;&amp;&#039; + sels[i].name + &#039;=&#039;
    for (var j=0; j&lt;sels[i].options.length; j++)
    {
      if (sels[i].options[j].selected)
      {
        q += escape(sels[i].options[j].value)+&#039;,&#039;;
      }
    }
  }

  // this would be a call to an ajax handline function,
  // passing the url of our php file to save the data as
  // an argument
  sndReq(&#039;common/saveFormData.php&#039;+q);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mycrazydream.net/wp/2008/12/save-an-html-form-with-ajax/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

