<?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/category/programming/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>Ajax &#8211; Post Multiple Select Values</title>
		<link>http://www.fettesps.com/ajax-post-multiple-select-values/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ajax-post-multiple-select-values</link>
		<comments>http://www.fettesps.com/ajax-post-multiple-select-values/#comments</comments>
		<pubDate>Tue, 04 Oct 2011 11:12:41 +0000</pubDate>
		<dc:creator>FettesPS</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[AJAX]]></category>

		<guid isPermaLink="false">http://www.fettesps.com/?p=1557</guid>
		<description><![CDATA[So this form is pretty basic, it has a select box (list box) filled with possible values. You can select all or some of the values and then submit it to the server via Ajax. The problem was when I grabbed the value from the select box I only got the last value selected, not [...]]]></description>
			<content:encoded><![CDATA[<p>So this form is pretty basic, it has a select box (list box) filled with possible values.  You can select all or some of the values and then submit it to the server via Ajax.  The problem was when I grabbed the value from the select box I only got the last value selected, not each. Regardless of if I was using POST or GET I still had to build the parameter list since that&#8217;s how XMLHttpRequest works.  So I looped through the list and tried using the same parameter name for each, then on the PHP end I had the same result &#8212; each parameter overwrote the previous one and I saw only the last result. It wasn&#8217;t until I stumbled upon <a href="http://forums.devshed.com/javascript-development-115/ajax-posting-a-form-with-multiple-values-an-array-for-the-535164.html">this post</a> that someone gave a decent suggestion, which was to put a [] at the end of each parameter name when building the query string and PHP would automatically interpret it as an array. Since his code was somewhat over complicated I thought I&#8217;d share my version of it:</p>
<p><strong>test-utility.php</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Test Utility&lt;/title&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;test-utility.js&quot;&gt;	&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;h1 align='center'&gt;Test Utility&lt;/h1&gt;

&lt;center&gt;

    &lt;p style=&quot;width:450px; text-align:justify;&lt;?php if($error) echo &quot;color:red;&quot; ?&gt;&quot;&gt;
        &lt;?php if($error) { ?&gt;
            &lt;strong&gt;Error:&lt;/strong&gt; &lt;?php echo $error; ?&gt;
        &lt;?php } ?&gt;
    &lt;/p&gt;

    &lt;form name='frmTestUtility' id='frmTestUtility' method='post' action=''&gt;
    &lt;table cellpadding=&quot;2&quot; cellspacing=&quot;2&quot; border=&quot;0&quot;&gt;
    &lt;tr&gt;
        &lt;td&gt;
            Listbox(s):&lt;br&gt;&lt;br&gt;
            &lt;div style=&quot;font-size:smaller&quot;&gt;(Hold CTRL to&lt;br&gt;select multiple)&lt;/div&gt;
        &lt;/td&gt;
        &lt;td align=&quot;center&quot;&gt;
            &lt;select name='listbox[]' id='listbox' multiple=&quot;multiple&quot;&gt;
                &lt;option value='123'&gt;123&lt;/option&gt;
                &lt;option value='abc'&gt;abc&lt;/option&gt;
                &lt;option value='alpha'&gt;alpha&lt;/option&gt;
                &lt;option value='beta'&gt;beta&lt;/option&gt;
                &lt;option value='gamma'&gt;gamma&lt;/option&gt;
            &lt;/select&gt;
            &lt;br&gt;
            &lt;input type=&quot;button&quot; name=&quot;all&quot; value=&quot;All&quot; onClick='javascript:select_all();'&gt;
            &lt;input type=&quot;button&quot; name=&quot;none&quot; value=&quot;None&quot; onClick='javascript:select_none();'&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td colspan=&quot;2&quot;&gt;
            &lt;input type=&quot;button&quot; name=&quot;submit&quot; onclick=&quot;javascript:run_queries();&quot; value=&quot;Run SQL&quot; /&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
    &lt;/table&gt;
    &lt;/form&gt;

    &lt;div id=&quot;ajax_results&quot;&gt;
        &amp;nbsp;
    &lt;/div&gt;
    &lt;/center&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p><strong>test-utility.js</strong></p>
<pre class="brush: jscript; title: ; notranslate">
function select_all() {
    var d = document.getElementById(&quot;listbox&quot;);
        for(var i=0;i&lt;d.length;i++) {
            d.options[i].selected = &quot;1&quot;;
        }
}

function select_none() {
    var d = document.getElementById(&quot;listbox&quot;);

    for(var i=0;i&lt;d.length;i++) {
        d.options[i].selected = &quot;&quot;;
    }
}

// Build the query string and submit it to the next page for processing
function run_queries() {
    var xmlhttp, url;&lt;/pre&gt;

    // For modern browsers
    if(window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();

    // for IE 5/6
    } else {
        xmlhttp = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
    }

    //  Rebuild the array of selected option boxes
    lb = document.getElementById(&quot;listbox&quot;);
    for(var i=0; i &lt; lb.length; i++) {
        if(lb[i].selected) {
            // Note the [] after the name
            url += &quot;&amp;lb[]=&quot; + lb[i].value;
        }
    }

    xmlhttp.open(&quot;GET&quot;,&quot;test-utility-ajax.php&quot; + url, false);
    xmlhttp.send();

    if (xmlhttp.status == 200) {
        document.getElementById(&quot;ajax_results&quot;).innerHTML = xmlhttp.responseText;
    } else {
        return false;
    }

    return false;
}
</pre>
<p><strong>test-utility-ajax.php</strong>br></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
  // As you can see PHP displays it as an array
  if($_POST} print_r($_POST);
?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fettesps.com/ajax-post-multiple-select-values/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>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>

