<?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>FettesPS &#187; JavaScript</title>
	<atom:link href="http://www.fettesps.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fettesps.com</link>
	<description>Fettes Programming Solutions</description>
	<lastBuildDate>Sun, 22 Jan 2012 18:21:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>PHP &#8211; Converting an Array to JSON</title>
		<link>http://www.fettesps.com/php-converting-an-array-to-json/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-converting-an-array-to-json</link>
		<comments>http://www.fettesps.com/php-converting-an-array-to-json/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 13:09:01 +0000</pubDate>
		<dc:creator>FettesPS</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://www.fettesps.com/?p=875</guid>
		<description><![CDATA[Every now and then I stumble upon a tidbit of information that just makes me want to kick myself. Today was one of those days. Just by chance I ended up at an entry on PHP.net while Googling another issue. Once I realized what this function was capable of I was torn between thinking &#8220;Wow, [...]]]></description>
			<content:encoded><![CDATA[<p>Every now and then I stumble upon a tidbit of information that just makes me want to kick myself.  Today was one of those days.  Just by chance I ended up at <a href="http://php.net/manual/en/function.json-encode.php">an entry on PHP.net</a> while Googling another issue.  Once I realized what this function was capable of I was torn between thinking &#8220;Wow, this is awesome!&#8221; and &#8220;Wow, I&#8217;m a dumbass!&#8221;</p>
<pre class="brush: php; title: ; notranslate">
$array = array (
    'alpha'=&gt;4,
    'beta'=&gt;9,
    'gamma'=&gt;3
);
echo json_encode($array)
</pre>
<p>You should then see something like the following:</p>
<pre class="brush: plain; title: ; notranslate">{&quot;alpha&quot;:4,&quot;beta&quot;:9,&quot;gamma&quot;:3}</pre>
<p>If you were manually processing the array and building a JSON object like I was, assume the face palm position.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fettesps.com/php-converting-an-array-to-json/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript&#8217;s Modulus &#8220;Bug&#8221;</title>
		<link>http://www.fettesps.com/javascripts-modulus-bug/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=javascripts-modulus-bug</link>
		<comments>http://www.fettesps.com/javascripts-modulus-bug/#comments</comments>
		<pubDate>Wed, 26 Jan 2011 13:22:25 +0000</pubDate>
		<dc:creator>FettesPS</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[jscript]]></category>
		<category><![CDATA[modulus]]></category>
		<category><![CDATA[visual basic]]></category>

		<guid isPermaLink="false">http://www.fettesps.com/?p=1244</guid>
		<description><![CDATA[I recently encountered an issue that caused me a bit of confusion. JavaScript was not calculating a modulus in the same manner that Windows Calculator or Visual Basic was. At first I had thought this to be a bug, but after doing a bit more research I discovered that it was actually giving the correct [...]]]></description>
			<content:encoded><![CDATA[<p>I recently encountered an issue that caused me a bit of confusion.  JavaScript was not calculating a modulus in the same manner that Windows Calculator or Visual Basic was.  At first I had thought this to be a bug, but after doing a bit more research I discovered that it was actually giving the correct answer and it was the Microsoft products that were giving me the wrong answer.  To help illustrate this issue, open up your Windows Calculator and enter <b>1.47 MOD 0.05</b> and then look at the <a title="0.02" alt="0.02">result</a>.  Now in your browser&#8217;s address bar enter <b>javascript:alert(1.47 % 0.05);</b> and press return.  <a title="0.0199999999999893" alt="0.0199999999999893">Notice the difference</a>?  Windows gives you a nice whole number to work with, and when you crunch the numbers in your head it makes sense.  </p>
<p>So what&#8217;s the solution?  It&#8217;s rather simple, actually.  Since the issue only pops it&#8217;s head up when you&#8217;re working with decimals, all you have to do is multiply it by the correct power of 10 and then do your calculations.  Once you have a result, divide it again by the same power of 10 and you have the answer.  So for example, in Canada lately there&#8217;s been a lot of talk about the Royal Mint wanting to stop making pennies and as a result all transactions will be rounded to the nearest 5 cents.  So lets look at a function that could be used to round a value down to a 5 cent increment:</p>
<pre class="brush: jscript; title: ; notranslate">
    // Enter a value in dollars and cents, such as 4.97 or 1.91
    var value = prompt(&quot;Please enter an amount&quot;,&quot;Amount&quot;);
    var balance_remainder = 0;
    var balance_sign = 1;

    if(isNaN(value)) {
        alert(&quot;Not a Number!&quot;);
        value = 0;

    } else {
        // NOTE: JS calculates a modulus on floating point numbers differently than some languages
        //       The solution is to multiply currencies by 100 before getting the modulus and then dividing the answer by 100                                                                              

        // Strip the negative off for now so it doesn't screw with the calculations
        if(value &lt; 0) {
            balance_sign = -1;
            value = value * -1;
        } else {
            balance_sign = 1;
        }

        // Calculate the remainder
        balance_remainder = (value * 100) % 5;
        balance_remainder = balance_remainder / 100;

        // Strip off the remainder
        if(balance_remainder &gt; 0) {
            value = value - balance_remainder;
            value = Math.round(value * 100) / 100;
        }

        // Re-sign the value
        value = value * balance_sign;
    }

    alert(&quot;Result: &quot; + value);
</pre>
<p>And there you have it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fettesps.com/javascripts-modulus-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Top Ten Web Design Pet Peeves</title>
		<link>http://www.fettesps.com/top-ten-web-design-pet-peeves/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=top-ten-web-design-pet-peeves</link>
		<comments>http://www.fettesps.com/top-ten-web-design-pet-peeves/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 15:57:21 +0000</pubDate>
		<dc:creator>FettesPS</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[shockwave]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://www.fettesps.com/?p=105</guid>
		<description><![CDATA[There&#8217;s some trends on the Internet that just wont die. I swear sometimes I don&#8217;t even know what decade it is when I click on a link and find an archaic HTML 3.2 driven site layered with frames and animated gifs. But what is even more disturbing is when you stagger into a site that [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s some trends on the Internet that just wont die.  I swear sometimes I don&#8217;t even know what decade it is when I click on a link and find an archaic HTML 3.2 driven site layered with frames and animated gifs. But what is even more disturbing is when you stagger into a site that was written only weeks ago and it looks like something you made in Grade 9 on your Packard Bell desktop.<br />
Every day I find my way on to some terribly produced site that makes me gag.  Here&#8217;s a short list of web design mistakes that drive me up the wall:</p>
<p><strong>10 &#8211; JavaScript Links</strong></p>
<p>This one isn&#8217;t always noticeable, when you use the website the way the designer expected you to use it.  What they did not expect was for you to ctrl+click or middle click a link to open it in a new tab. Perhaps you just wanted to copy the URL so you can send it to a friend?  Unfortunately far too many developers leave off the <em>href attribute</em> when they use an onClick, or they needlessly make their links use JavaScript in order to do something silly like open it as a popup.</p>
<p><strong>9 &#8211; Denying Right Click</strong></p>
<p>I can&#8217;t help but laugh every time I see this one.  Almost all browsers these days override the developer&#8217;s attempt to stop you from right clicking.  Instead what happens is they get an alert saying its not allowed at the same time as the right click menu.  If you are that worried about me stealing your image, there are better ways to stop it.  Trying to deny right clicks just annoys the user, and provides them no benefit.</p>
<p><strong>8 &#8211; Under Construction</strong><br />
<img class="aligncenter size-full wp-image-299" title="Under Construction" src="http://www.fettesps.com/wp-content/uploads/2009/06/bigtriangle2.gif" alt="Under Construction" width="88" height="90" style="float:right; margin: 30px 10px 30px 30px;" />
<div style="width:380px; text-align: justify; margin-bottom: 10px;color:#AEC8E6;">
Virtually every website is under construction, they continue to evolve and add content.  Putting an Under Construction header (or worse, an animated gif of some stick men construction workers) on your site is like putting a <em>Caution &#8211; Hot</em> sticker on a stove.  What makes this problem even worse is when you eventually abandon your website, because you got bored of it or ran out of clip art, it will permanently bear this <em>Under Construction</em> warning until the end of time.</div>
<p><strong>7 &#8211; Splitting Content</strong></p>
<p>I appreciate the fact that you might be trying to break up the article to make it seem less intimidating to read, but you can solve that issue by just adding some white space.  I can handle more than three paragraphs at a time.  We all know the real reason you broke your single page article into six pages was just so you could get more ad impressions.  But guess what, when I got the &#8220;continued on page 2&#8243; link I just closed the page.</p>
<p><strong>6 &#8211; All Flash Websites</strong></p>
<p>You&#8217;re a graphic designer, not a web designer.  Stop trying to be both.  Not only is the noise and &#8220;flashiness&#8221; of your website annoying, but it&#8217;s extremely hard to navigate your site.  How am I supposed to know that if I hover my mouse over bird another the link to the gallery will appear.  To make matters worse, once I find the section I need I can&#8217;t even bookmark it because your whole page exists as one URL.  So each time I come here I have to watch your long and useless intro, then stumble through your horrible menu system.</p>
<p><strong>5 &#8211; Splash Pages</strong></p>
<p>Wow, you know Photoshop or Flash.  I&#8217;m not impressed.  In fact, I&#8217;m annoyed because I just had to perform yet another click to get to the content of your page.  To make matters worse, you tried to be creative with your placement of the enter button and I can&#8217;t find it on your splash page at all.</p>
<p><strong>4 &#8211; Resizing the Window</strong></p>
<p>I like my window the size it is.  If its maximized, it&#8217;s because I wanted it maximized.  If it&#8217;s only taking up half my screen, it&#8217;s most likely because I needed the other half for something else.  Yes, your crappy flash page was meant to be viewed at 800&#215;600, but I will resize it myself if I need to.</p>
<p><strong>3 &#8211; Videos that Auto Play</strong></p>
<p>Chances are that I have no interest in the videos you&#8217;ve put on your site.  If I wanted to find a video I would have searched on Youtube or a similar engine.  Your video may be relavent and useful to me, but please give me the option to start it when I&#8217;m ready.  I often open many tabs at once and don&#8217;t get to them for some time.  Having to click on each one, scroll through pages of posts and try and find the source of the talking I hear, and then stopping it is really annoying.  What&#8217;s even more annoying is when you have 10 videos on your main page that all start playing at once &#8212; seriously, what made you think that would be a good idea?</p>
<p><strong>2 &#8211; Music</strong></p>
<p>Even more annoying than videos is background music.  We all have very different tastes in music, I probably don&#8217;t like what you like.  In fact, I probably hate it.  And what I&#8217;d probably hate even more is for it to scare the living crap out of me when I open your site at 3 am and have neglected to turn my speakers off.  I have never seen a website that needed background music, never.  I don&#8217;t care if it&#8217;s a website for your favourite band, it doesn&#8217;t need to auto play.  If you feel you need sound on your site, follow this one simple rules  give the user the option of if and when they&#8217;d like to hear it.</p>
<p><strong>1 &#8211; Click Here&#8230;</strong></p>
<p>Some of you will think it&#8217;s silly that I put this on the top of my list.  But this one is huge for me because it is a plague that has infested the majority of the Internet.  It&#8217;s become so popular and normal to see on a website that I continuously have intelligent, highly educated clients handing me text full of &#8220;click here&#8230;&#8221; links.  There is no need for this, link the title or action as you mention it, you will look far more professional if you do.</p>
<p>So, what are your pet peeves?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fettesps.com/top-ten-web-design-pet-peeves/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>JavaScript &#8211; Hide or Show an Element</title>
		<link>http://www.fettesps.com/javascript-hide-or-show-an-element/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=javascript-hide-or-show-an-element</link>
		<comments>http://www.fettesps.com/javascript-hide-or-show-an-element/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 12:30:20 +0000</pubDate>
		<dc:creator>FettesPS</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[dhtml]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[js]]></category>

		<guid isPermaLink="false">http://www.fettesps.com/?p=280</guid>
		<description><![CDATA[Just about every site I&#8217;ve designed has made use of this code block. It utilizes a combination of JavaScript, CSS and some HTML DOM knowledge to get the job done.  Most often I use this to make dynamic menus however the uses are endless.  For this example I will use it for something more simple. [...]]]></description>
			<content:encoded><![CDATA[<p>Just about every site I&#8217;ve designed has made use of this code block.  It utilizes a combination of JavaScript, CSS and some HTML DOM knowledge to get the job done.  Most often I use this to make dynamic menus however the uses are endless.  For this example I will use it for something more simple.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras dignissim, quam sed pellentesque eleifend, nisi erat facilisis quam, a viverra lorem arcu ut dolor. Morbi in magna mi, vel malesuada diam. Proin pulvinar ultricies aliquam. Sed tellus neque, facilisis eget sagittis eu, cursus in turpis. Phasellus vestibulum turpis nibh. Nam porta congue tellus bibendum sodales. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Duis tellus tortor, aliquet vel mattis vel, sagittis id eros. Ut lacinia lobortis volutpat. Nunc rhoncus sem eu augue mollis dapibus.&lt;br /&gt;
&lt;a href=&quot;javascript:;&quot; onClick=&quot;showLayer('more_content')&quot;&gt;Show&lt;/a&gt;&lt;/p&gt;
&lt;p id=&quot;more_content&quot;&gt;
Fusce sit amet diam odio. Quisque mattis sagittis dui ut malesuada. Curabitur felis velit, varius id scelerisque a, facilisis eu felis. Cras placerat urna ut nulla vulputate quis dignissim arcu tempor. Aliquam laoreet varius sollicitudin. Pellentesque feugiat vehicula risus, ut tristique massa hendrerit ac. Nulla facilisi. Phasellus et nulla erat, sed viverra enim. Curabitur faucibus mi eget quam ultrices non hendrerit tortor consectetur. Etiam iaculis massa et mauris vulputate rhoncus. Proin dapibus mauris in dolor sagittis ut elementum purus mattis.
&lt;br /&gt;&lt;a href=&quot;javascript:;&quot; onClick=&quot;hideLayer('more_content')&quot;&gt;Hide&lt;/a&gt;
&lt;/p&gt;
</pre>
<p>At this point your page will render both paragraph blocks.  In order to hide the second by default we have to add some CSS styling.  I could have done this inline for the example however since I consider that to be bad coding practice I will create a style block for that.</p>
<pre class="brush: css; title: ; notranslate">p#more_content {
display: none;
}</pre>
<p>Now your second paragraph will be hidden by default and the user will have to hit the Show link in order to expand the content. In order to make that functional you will need to add the following JavaScript code.</p>
<pre class="brush: jscript; title: ; notranslate">function hideLayer(whichLayer) {
var menuGroup;
if (document.getElementById) {
// Standard method for modern browsers
menuGroup = document.getElementById(whichLayer).style;

} else if (document.all) {
// For Old IE versions
menuGroup = document.all[whichLayer].style;

} else if (document.layers) {
// For Netscape Navigator 4
menuGroup = document.layers[whichLayer].style;
}
menuGroup.display = &quot;none&quot;;
}

function showLayer(whichLayer) {
var menuGroup;
if (document.getElementById) {
// Standard method for modern browsers
menuGroup = document.getElementById(whichLayer).style;
} else if (document.all) {
// For Old IE versions
menuGroup = document.all[whichLayer].style;
} else if (document.layers) {
// For Netscape Navigator 4
menuGroup = document.layers[whichLayer].style;
}
menuGroup.display = &quot;block&quot;;
}</pre>
<p>This code block could be simplified considerably by using only the getElementById() method, however that will remove it&#8217;s backwards compatibility with older browsers. Though the percentage of users visiting with Netscape Navigator 4 or Internet Explorer 4 are extremely low, it could happen, so I have always left those extra lines in just to make sure.</p>
<p>You can also build on this a bit and make it one function that alternates between showing and hiding the div by changing the last line of code to <em>menuGroup.display = menuGroup.display? &#8220;&#8221;:&#8221;block&#8221;;</em>.</p>
<p><a href="http://www.fettesps.com/hideshow.html" target="_new">See it in action</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fettesps.com/javascript-hide-or-show-an-element/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>JavaScript &#8211; Auto Set Focus When Page is Done Loading</title>
		<link>http://www.fettesps.com/javascript-auto-set-focus-when-page-is-done-loading/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=javascript-auto-set-focus-when-page-is-done-loading</link>
		<comments>http://www.fettesps.com/javascript-auto-set-focus-when-page-is-done-loading/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 22:22:46 +0000</pubDate>
		<dc:creator>FettesPS</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[auto focus]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[login page]]></category>
		<category><![CDATA[set focus]]></category>

		<guid isPermaLink="false">http://www.fettesps.com/?p=272</guid>
		<description><![CDATA[I use this block of code quite often. Almost every project I develop has a login page and I always toss this in to give it that subtle boost to the overall user experience. Once the page has loaded, the cursor location will automatically be set to the username field so the user doesn&#8217;t have [...]]]></description>
			<content:encoded><![CDATA[<p>I use this block of code quite often. Almost every project I develop has a login page and I always toss this in to give it that subtle boost to the overall user experience.  Once the page has loaded, the cursor location will automatically be set to the username field so the user doesn&#8217;t have to grab their mouse or tab over to it just to log in.  I&#8217;ve seen far too many site that don&#8217;t use this and it always frustrates me.</p>
<pre class="brush: jscript; title: ; notranslate">&lt;script type=&quot;text/javascript&quot;&gt;
	window.onload = function() {
		document.forms[0].username.focus();
	}
&lt;/script&gt;</pre>
<p>I would also recommend this on any page that has a form element on it that must be filled out.  However be careful not to use it on a page that has a form field that the user may not be interested in.  A good example of bad placement for this block of code is <a href="http://www.avnads.com" target="_new">AVN Ads</a> which sets focus to the search box instead of the username field.  Every time I go there I get half way through typing my username and password before it jumps up to the search box and I in my haste I end up typing my password into the search field for all the world to see. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.fettesps.com/javascript-auto-set-focus-when-page-is-done-loading/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>JavaScript &#8211; Creating Default Arguments</title>
		<link>http://www.fettesps.com/javascript-creating-default-arguments/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=javascript-creating-default-arguments</link>
		<comments>http://www.fettesps.com/javascript-creating-default-arguments/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 01:57:26 +0000</pubDate>
		<dc:creator>FettesPS</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[default arguments]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[ternary]]></category>

		<guid isPermaLink="false">http://www.fettesps.com/?p=221</guid>
		<description><![CDATA[I ran into an interesting quirk with JavaScript yesterday, one I&#8217;m surprised I hadn&#8217;t noticed before.  JavaScript does not allow you to give arguments default values when defining functions.  So after a bit of tinkering, I came up with a solution. Of course you could use a ternary operator if you prefer, however I know [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into an interesting quirk with JavaScript yesterday, one I&#8217;m surprised I hadn&#8217;t noticed before.  JavaScript does not allow you to give arguments default values when defining functions.  So after a bit of tinkering, I came up with a solution.</p>
<pre class="brush: jscript; title: ; notranslate">
function lorum(x, y) {

	if(typeof(x) == &quot;undefined&quot;) {
		x = 100;
	}
	if(typeof(y) == &quot;undefined&quot;) {
		y = 500;
	}

	// ...
}
</pre>
<p>Of course you could use a ternary operator if you prefer, however I know I&#8217;m not alone when I say that I do not like them.  In any case, here&#8217;s an example using them:</p>
<pre class="brush: jscript; title: ; notranslate">
function ipsum(i, j) {

	i = typeof(i) == &quot;undefined&quot; ? 100 : i;
	j = typeof(j) == &quot;undefined&quot; ? 500 : j; 

	// ...
}
</pre>
<p>Despite its reduced code space, I prefer not to use them as they can be confusing at first glance.  But to each his own.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fettesps.com/javascript-creating-default-arguments/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Working With Dojo&#8217;s DateTextTime Field</title>
		<link>http://www.fettesps.com/working-with-dojos-datetexttime-field/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=working-with-dojos-datetexttime-field</link>
		<comments>http://www.fettesps.com/working-with-dojos-datetexttime-field/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 16:21:47 +0000</pubDate>
		<dc:creator>FettesPS</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[date format]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[dhtml]]></category>
		<category><![CDATA[dijit]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[field validation]]></category>

		<guid isPermaLink="false">http://www.fettesps.com/?p=191</guid>
		<description><![CDATA[I&#8217;ve been working with Dojo for a couple of weeks now, and let me just say I&#8217;ve fallen in love with it and all it has to offer. It allows me to quickly and efficiently integrate dynamic content into all of my web projects with a very small learning curve. Despite the abundant amount of [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working with Dojo for a couple of weeks now, and let me just say I&#8217;ve fallen in love with it and all it has to offer. It allows me to quickly and efficiently integrate dynamic content into all of my web projects with a very small learning curve. </p>
<p>Despite the abundant amount of documentation out there I still find myself getting stuck on the odd little thing.  For example, I was working with Dijit&#8217;s DateTextTime field and simply could not get it to take a date I passed in.  If I did it directly through HTML by setting the value attribute it would work, however when setting it in JavaScript as part of my AJAX call it would fail every time.  I dugg around the Dojo community eventually finding someone who had the same issue and had managed to solve it &#8220;after several hours of trial and error&#8221; but sadly he neglected to post his solution.  Thus I wanted to make mine available for anyone who finds themself working on the same problem.</p>
<p>I was working with the <a href="http://www.dojotoolkit.org/book/dojo-book-0-9/part-2-dijit/form-validation-specialized-input/textbox-validating-currency-number">Dojo Toolkit</a> as a reference and sadly it only stated that you used the SetValue() method to assign a date, but it did not provide the required syntax. After much trial and error I eventually discovered it wasn&#8217;t expecting that I pass it in as a string at all, rather it had to be set as a JavaScript date object first.  So here is the required steps to assign a date to a DateTextTime field:</p>
<pre class="brush: plain; title: ; notranslate">
// Now
var dateA = new Date(); 

// January 1, 2009
// Note that the months start from 0 but days start from 1
var dateB = new Date(2009, 0, 1); 

// Parsing a string returne from MYSQL, in the format of YYYY-MM-DD
var dateC = new Date(data[&quot;ExpiryDate&quot;].substr(0,4), parseInt(data[&quot;ExpiryDate&quot;].substr(5,2))-1, data[&quot;ExpiryDate&quot;].substr(8,2)); 

// Pass Date Objects into Dijit
dijit.byId(&quot;registered&quot;).setValue(dateA);
dijit.byId(&quot;bdate&quot;).setValue(dateB);
dijit.byId(&quot;expiryDate&quot;).setValue(dateC);

// Reference
// http://www.w3schools.com/jS/js_obj_date.asp</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fettesps.com/working-with-dojos-datetexttime-field/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Email Obfuscation</title>
		<link>http://www.fettesps.com/email-obfuscation/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=email-obfuscation</link>
		<comments>http://www.fettesps.com/email-obfuscation/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 04:48:43 +0000</pubDate>
		<dc:creator>FettesPS</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[obfuscate]]></category>

		<guid isPermaLink="false">http://www.fettesps.com/blog/?p=50</guid>
		<description><![CDATA[As we all know spam is a plague that has spread to every far corner of the Internet.  Spam-bots collect our email addresses in many ways, but in my opinion the most likely way they&#8217;ll get your email address is from scraping webpages such as forums, where you email may be listed.  So when you&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>As we all know spam is a plague that has spread to every far corner of the Internet.  Spam-bots collect our email addresses in many ways, but in my opinion the most likely way they&#8217;ll get your email address is from scraping webpages such as forums, where you email may be listed.  So when you&#8217;re building your site and you want to put an &#8220;email me&#8221; link you should be very careful about doing so.  Once the bots find it they&#8217;ll start sending you endless offers to buy Viagara an Cialis.</p>
<p>So what can you do to stop this?  There are many solutions!  But today I want to offer you a simple JavaScript file that will encrypt your all email addresses on your page automatically.  It can be downloaded from <a href="http://voynex.com/emailguard">Voynex</a>, however they don&#8217;t really offer a good explanation on how to use it.  So here is a step by step:</p>
<ol>
<li>Download the Email Guard script from Voynex&#8217;s site</li>
<li>Extract the files and upload xmailguard.js to your site, I usually have a directory called &#8220;scripts&#8221; in the root of each site</li>
<li>In any page you want to have your emails encrypt link the script by adding this line to the top: &lt;script language=&#8221;javascript&#8221; type=&#8221;text/javascript&#8221; src=&#8221;/scripts/xmailguard.js&#8221;&gt;&lt;/script&gt;</li>
<li>Initialize the script by adding another script block : &lt;script language=&#8221;javascript&#8221; type=&#8221;text/javascript&#8221;&gt;xmgInit()&lt;/script&gt;</li>
<li>Now you have to type your email links a bit differently, instead of &lt;a href=&#8221;mailto:email@address.com&#8221;&gt;email@address.com&lt;/a&gt; you will have to code your links to &lt;a href=&#8221;mail_to_email_at_address.com&#8221;&gt;email_at_address.com&lt;/a&gt; and when the page loads it will rewrite them for you.   If you are using PHP this line will do most of the work for you: $email = str_replace(&#8220;@&#8221;, &#8220;_at_&#8221;, $email);</li>
<li>Now its possible that some bots will render the javascript first before doing their dirty work, but from my experience I have found they don&#8217;t process the javascript.  You can also customize the encrypted syntax you want to use by tweaking the first couple of lines in xmailguard.js</li>
</ol>
<p>Now your email addresses are safe!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fettesps.com/email-obfuscation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

