<?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>Krio Media &#187; JavaScript</title>
	<atom:link href="http://www.krio.me/category/development-info/javascript-tutorials-learn-js/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.krio.me</link>
	<description></description>
	<lastBuildDate>Wed, 01 Jun 2011 16:24:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Sort &amp; Remove Duplicates in JavaScript Arrays</title>
		<link>http://www.krio.me/sorting-and-removing-duplicates-in-javascript-arrays/</link>
		<comments>http://www.krio.me/sorting-and-removing-duplicates-in-javascript-arrays/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 06:21:22 +0000</pubDate>
		<dc:creator>Kevin Rio</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.krio.me/?p=1312</guid>
		<description><![CDATA[JavaScript arrays can be somewhat intimidating. They tend to not have all the available functions/methods that other languages like PHP and Ruby have for manipulating arrays.  Making a JS array unique isn&#8217;t a simple one-liner. This short article is for developers trying to make a JavaScript array unique without leaving holes in your array. Sorting [...]]]></description>
			<content:encoded><![CDATA[<p>JavaScript arrays can be somewhat intimidating. They tend to not have all the available functions/methods that other languages like PHP and Ruby have for manipulating arrays. <span id="more-1312"></span></p>
<p>Making a JS array unique isn&#8217;t a simple one-liner. This short article is for developers trying to make a JavaScript array unique without leaving holes in your array. Sorting an array in JavaScript is simple in most cases. Just call the sort() method on the array like so.</p>
<pre class="brush: php; title: ;">
var my_array = [5, 2, 4, 6, 9];
my_array.sort();
</pre>
<p>One caveat to be aware of with this method of sorting is that it performs a non-lexicographical sort, which might be confusing for human users if you display it on screen. Depending on your requirements, you might want to change your sorting algorithm. Check out Brian Huisman&#8217;s <a title="Lexicographical sorting in javascript" href="http://my.opera.com/GreyWyvern/blog/show.dml/1671288" target="_blank">article on the subject</a>. </p>
<p>After sorting the array, the following snippet will remove any duplicate entries</p>
<pre class="brush: php; title: ;">
for ( var i = 1; i &lt; my_array.length; i++ ) {
    if ( my_array[i] === my_array[ i - 1 ] ) {
        my_array.splice( i--, 1 );
    }
}
</pre>
<p>This will iterate over each element in the array, attempting to find elements where the value is equal to the previous value. If they are equal, we have found a duplicate so we remove it using splice.</p>
<p>A complete function for sorting and making an array unique in JavaScript would look like the following</p>
<pre class="brush: php; title: ;">
function sort_and_unique( my_array ) {
	my_array.sort();
	for ( var i = 1; i &lt; my_array.length; i++ ) {
		if ( my_array[i] === my_array[ i - 1 ] ) {
					my_array.splice( i--, 1 );
		}
	}
	return my_array;
};
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.krio.me/sorting-and-removing-duplicates-in-javascript-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Image Loader Plugin</title>
		<link>http://www.krio.me/jquery-image-loader-plugin/</link>
		<comments>http://www.krio.me/jquery-image-loader-plugin/#comments</comments>
		<pubDate>Mon, 13 Dec 2010 04:20:23 +0000</pubDate>
		<dc:creator>Kevin Rio</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.krio.me/?p=1297</guid>
		<description><![CDATA[This is a JavaScript file released as a jQuery plugin that loads images in a visually appealing way. Instead of the typical block loading that HTML employs while loading images, this plugin waits until the entire image is downloaded then fades it in. This plugin simplifies the process of loading images. It is easily applied [...]]]></description>
			<content:encoded><![CDATA[<p>This is a JavaScript file released as a jQuery plugin that loads images in a visually appealing way. Instead of the typical block loading that HTML employs while loading images, this plugin waits until the entire image is downloaded then fades it in. <span id="more-1297"></span>This plugin simplifies the process of loading images. It is easily applied to wrappers so that it will load all of the images within it. Its main purpose is to assist web developers and designers in improving their user interfaces.</p>
<h3>Image Loading Instructions</h3>
<ul>
<li>Include jQuery</li>
<li>Include jquery.krioImageLoader.js</li>
<li>Instantiate the plugin on the wrapper</li>
<li>$(&#8220;#test&#8221;).krioImageLoader();</li>
<li>Watch it load</li>
</ul>
<p><a href="http://krio.me/scripttest/imgLoader/" target="_blank">View the Demo</a><br />
<a href="http://github.com/krio/jquery-image-loader-plugin" target="_blank">Download or fork on GitHub</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.krio.me/jquery-image-loader-plugin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript Form Validation Essentials Chapter 1</title>
		<link>http://www.krio.me/javascript-form-validation-essentials-chapter-1/</link>
		<comments>http://www.krio.me/javascript-form-validation-essentials-chapter-1/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 03:58:57 +0000</pubDate>
		<dc:creator>Kevin Rio</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[form validation]]></category>
		<category><![CDATA[javascript turorials]]></category>

		<guid isPermaLink="false">http://kriomedia.com/?p=139</guid>
		<description><![CDATA[In this series we are going to learn how to validate input using JavaScript. We will not allow a user to submit a form without entering the appropriate information. This will help to greatly reduce the amount of spam that you receive, along with minimizing security risks. This is the first entry in a series [...]]]></description>
			<content:encoded><![CDATA[<p>In this series we are going to learn how to validate input using JavaScript. We will not allow a user to submit a form without entering the appropriate information. This will help to greatly reduce the amount of spam that you receive, along with minimizing security risks.</p>
<p><span id="more-139"></span>This is the first entry in a series that will cover many different types of input. First, we will make a form that can only be submitted when a user inputs a proper email address.</p>
<h1>The Form</h1>
<p>First things first, let build our HTML form.</p>
<pre class="brush: xml; title: ;">

&lt;form method=&quot;post&quot; action=&quot;&quot;&gt;

&lt;input id=&quot;email&quot; type=&quot;text&quot; name=&quot;email&quot;/&gt;

&lt;input type=&quot;submit&quot; name=&quot;emailSubmit&quot; onclick=&quot;return checkEmail();&quot;/&gt;

&lt;/form&gt;
</pre>
<p>Anything out of the ordinary here? First, you should notice the id=&#8221;email&#8221; in the email input box. Because of this id=&#8221;email&#8221; we are able to find out what the user has entered using JavaScript. Next,  in the submit input box, you should see onclick=&#8221;return checkEmail();&#8221;, which is what tells JavaScript to call our JavaScript function, which will validate the email address. &#8216;return&#8217; is used because if the function returns false, it will not submit the form, but if it returns true, the form will be submitted.</p>
<h1>The JavaScript</h1>
<p>Here is the JavaScript for the validation. This should be placed between the head tags of the HTML document.</p>
<pre class="brush: jscript; title: ;">

&lt;script type=&quot;text/javascript&quot;&gt;

 function checkEmail()
 {

 var email = document.getElementById('email').value;

 emailExpression = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;

 if(!email.match(emailExpression))
 {
 alert(&quot;Please enter a valid email!&quot;);
 return false;
 }

 return true;
 }

 &lt;/script&gt;
</pre>
<p>First we create the function checkEmail which will run when the submit button is pressed. Next we grab what the user has entered in the email box with the line: var email = document.getElementById(&#8216;email&#8217;).value; We store this value in the email variable. Next, we create our regular expression, which will be used to validate the email address.</p>
<p>You will then find an IF statement. This is used to actually compare the regular expression to the email variable, which we got from the form. If it does not match, an alert is placed on screen, and the form IS NOT submitted, however if it is an email address, the statement returns true and the form is submitted as normal.</p>
<p>I hope that this helps you begin to understand how you can validate forms on the client side using JavaScript. I will be expanding this series to include new types of input validation and ways of notifying the user.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krio.me/javascript-form-validation-essentials-chapter-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

