<?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>BIT Consultants &#187; Web</title>
	<atom:link href="http://www.bitconsultants.net/tag/web/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bitconsultants.net</link>
	<description></description>
	<lastBuildDate>Sat, 28 Jan 2012 02:19:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Getting Started: How the Interwebs Work</title>
		<link>http://www.bitconsultants.net/2008/getting-started-how-the-interwebs-work/</link>
		<comments>http://www.bitconsultants.net/2008/getting-started-how-the-interwebs-work/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 02:34:27 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.bitconsultants.net/?p=185</guid>
		<description><![CDATA[There are a ton of places on the web to learn HTML, so I kind of wonder why I am writing this in the first place. I<a href="http://www.bitconsultants.net/2008/getting-started-how-the-interwebs-work/"> Read More...</a>]]></description>
			<content:encoded><![CDATA[<p>There are a ton of places on the web to learn HTML, so I kind of wonder why I am writing this in the first place. I think that it was important in my quest to learn how to program that I was looking ahead at what I would be able to do, because the stuff I made at first was less than impressive.</p>
<p>This is a guide to hopefully help in your learning how to program for the web, split into parts. I am going to discuss how the web works, how to make a simple page and understand what is happening when it&#8217;s requested. Later, we will learn how to style the page (CSS), how to manipulate the page (using Javascript) and how to do some server-side programming (PHP and MySQL).</p>
<h3>I&#8217;ll keep it as short as possible</h3>
<p>Here is something you will likely hear: the web is a client-server model. &#8220;What is a client?&#8221;, you may ask. &#8220;What is a server?&#8221;, you may follow up. Well, they are computers, not much different from the one you are sitting at. You, looking at the page through your browser, are the client; my computer (the server) is running some free software called Apache, allowing me to share this content with you.</p>
<p>Buildings have addresses, so do computers. Your computer&#8217;s internet address is called an IP (Internet Protocol) address and it uniquely identifies your computer online. It is in the format 123.123.123.123 (where the number 123 could be any number between 0 and 255). With your IP address, I can see if your computer is online (as long as it&#8217;s not specially configured to hide) using a program called ping. If you were running Apache, like I am, I could see files that you were serving using your IP address. Google&#8217;s IP address is 74.125.67.100, try going to <a href="http://74.125.67.100" target="_blank">http://74.125.67.100</a>. That is exactly the same as going to <a href="http://google.com" target="_blank">http://google.com</a>, because that is one of their server&#8217;s IP address. Domain names (like google.com, whitehouse.gov or unitedway.org) are a system setup to simplify the requests that clients have to make. It would be a pain to try and remember 74.125.67.100, rather than google.com; I think of it like saying: &#8220;we&#8217;re located right next to the huge statue you can see from miles away&#8221; rather than 241123 West 53rd Street or 63.23211 latitude by -71.343219 longitude. There are several (but not quite as many as you would think) DNS (Domain Name Servers) Servers. By the way, I realize DNS Server is redundant. Regardless, these servers purpose is to map your requests to domain names to the corresponding IP address, kind of like phone operators did in the days of yore. You say &#8220;google.com&#8221;, it says &#8220;74.125.67.100&#8243;. Have I made that abundantly clear?</p>
<h3>Requesting files</h3>
<p>When the server receives a request, it looks for the requested file and transmits the content of that file to your computer. Many requests are implied; for instance, <a href="http://www.google.com/" rel="nofollow">http://www.google.com/</a> is not a file, it is just an address. The file you are actually viewing is <a href="http://www.google.com/index.html" rel="nofollow">http://www.google.com/index.html</a> (or <a href="http://74.125.67.100/index.html)" rel="nofollow">http://74.125.67.100/index.html)</a>. There is nothing magical about this. It&#8217;s important to realize that this is really not much different than looking at &#8220;My Documents\synergy.docx&#8221;, it is just a regular old file that is in a folder. Regarding index.html: server software, like Apache, is setup to show specific files if none are requested, if a non-existent file is requested or if a file you are not authorized to view is requested. There is no doubt that you have been served a 404 (resource not found) page before, and maybe even a 403 (access denied), let&#8217;s not forget the dreaded 500 (internal server error).</p>
<h3>The HTTP Protocol</h3>
<p>HTTP (Hyper Text Transfer Protocol) is the protocol that web browsers and web servers use to communicate with each other over the Internet. It is used by web browsers and web servers to talk to one another. Clients (web browsers) send requests to web servers for web elements such as web pages and images. After the request is processed by a server, the connection between client and server across the Internet is disconnected.  A new connection must be made for each request.  Most protocols are connection oriented, meaning that the two computers communicating with each other keep the connection open over the Internet.</p>
<h3>Summary of a Request</h3>
<p>When you type a URL into a web browser, this is what happens:</p>
<ol>
<li>Type a URL in (domain or IP address), domain names get checked against DNS</li>
<li>The web browser connects to the server and sends an HTTP request 	for a file.</li>
<li>The server receives the request and checks for the requested page. 	If the page exists, the server sends it.  If the server cannot 	find the requested page, it will send an HTTP 404 error message.</li>
<li>The web browser receives the page back and the connection is closed.</li>
<li>The browser then parses through the page and looks for other page 	elements it needs to complete the web page.  These usually include 	images, javascript files, css files, flash, etc.</li>
<li>For each element needed, the browser makes additional connections and 	HTTP requests to the server for each element.</li>
<li>When the browser has finished loading all images, flash, etc. the 	page will be completely loaded in the browser window.</li>
</ol>
<p>The web browser then renders HTML markup into fancy looking webpages (like this one). In summary, a lot of things are going on behind the scenes of the web; though it seems quite complex, it is really quite simple to understand. We will cover HTML in our next article.</p>
<p>Thanks for reading!</p>]]></content:encoded>
			<wfw:commentRss>http://www.bitconsultants.net/2008/getting-started-how-the-interwebs-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Form Validation: theory and practice</title>
		<link>http://www.bitconsultants.net/2008/jquery-form-validation-theory-and-practice/</link>
		<comments>http://www.bitconsultants.net/2008/jquery-form-validation-theory-and-practice/#comments</comments>
		<pubDate>Sun, 27 Jan 2008 21:37:30 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.bitconsultants.net/?p=173</guid>
		<description><![CDATA[jQuery makes it very easy to validate forms. There are a number of useful plugins, the most prominent being validate. If you are wanting something very lightweight<a href="http://www.bitconsultants.net/2008/jquery-form-validation-theory-and-practice/"> Read More...</a>]]></description>
			<content:encoded><![CDATA[<p>jQuery makes it very easy to validate forms. There are a number of useful plugins, the most prominent being <a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/" target="_blank">validate</a>. If you are wanting something very lightweight or are just interested in how something like this works, read on. The $.each function allows you to iterate over collections in jQuery, it is really one of the most useful utility methods available. We can iterate over all input elements on a page using $.each like this<br />
<script type="text/javascript"><!--
google_ad_client = "pub-4761320180230999";
/* 336x280, created 4/15/10 */
google_ad_slot = "4518447987";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<pre class="brush: jscript; title: Code Example; notranslate">
var input_count = 0;

$(document).ready(function(){
	$.each($('input'), function(index, value){
		input_count++;
	});
	console.log(&quot;Number of inputs:  %i&quot;,  input_count);//use Firebug, not alert() !
});
</pre>
<h3>Iterating Over Text Inputs</h3>
<p>There is a problem with the above code, any input elements (including buttons) are going to be iterated over, so let&#8217;s use a more specific selector to only retrieve input elements of type &#8220;text&#8221;</p>
<pre class="brush: jscript; title: Code Example; notranslate">

...

$.each($('input[type=&quot;text&quot;]'), function(index, value){

...
</pre>
<h3>Required Elements</h3>
<p>Okay, now we can iterate over our text inputs. So, where to go from here? Do we check that each item has a value? What if some items aren&#8217;t required? The easiest way I&#8217;ve found to do this is to use a class on required items (I usually call it &#8220;required&#8221; (creative, huh?)).</p>
<pre class="brush: xml; title: Code Example; notranslate">
...
&lt;form action=&quot;&quot; method=&quot;POST&quot; id=&quot;login_form&quot;&gt;
	&lt;dl&gt;
	  &lt;dt&gt;
		&lt;dd&gt;Username &lt;span class=&quot;req&quot;&gt;*&lt;/span&gt;&lt;/dd&gt;
		&lt;dd&gt;&lt;input type=&quot;text&quot; name=&quot;username&quot; class=&quot;required&quot; maxlength=&quot;7&quot; /&gt;&lt;/dd&gt;
		&lt;dd&gt;Password &lt;span class=&quot;req&quot;&gt;*&lt;/span&gt;&lt;/dd&gt;
		&lt;dd&gt;&lt;input type=&quot;text&quot; name=&quot;password&quot; class=&quot;required&quot; maxlength=&quot;7&quot; /&gt;&lt;/dd&gt;
		&lt;dd&gt;Favorite Color&lt;dd&gt;
		&lt;dd&gt;&lt;input type=&quot;text&quot; name=&quot;username&quot; /&gt;&lt;/dd&gt;
		&lt;dd&gt;Finish&lt;/dd&gt;
		&lt;dd&gt;&lt;input type=&quot;submit&quot; name=&quot;submit&quot; /&gt;&lt;/dd&gt;
	  &lt;/dt&gt;
	&lt;/dl&gt;
&lt;/form&gt;
...
</pre>
<p>Now we can check which fields are required and cancel form submission if they are empty. Getting rid of our input counter variable, here is the new code</p>
<pre class="brush: jscript; title: Code Example; notranslate">
$(document).ready(function(){
	$('#login_form').submit(function(){//add an onsubmit event handler to our form
		var blank_fields = false;//initialize a generic error detector
		$.each($('input[type=&quot;text&quot;]'), function(index, value){
			var t = $(this);//limit the number of new jQuery objects created
			if(t.hasClass('required')){//we know it is required
				if(t.val() == &quot;&quot; || t.val() === undefined){
					console.error('%s can not be blank', t.attr('name'));
					blank_fields = true;
				}
			}
		});
		return !blank_fields;//if there are no blank fields, submit
	});
});
</pre>
<p>That is a mouthful, but it is actually quite simple. When our form is submitted, we iterate over each input item to see if it is required. If it&#8217;s required, check to see if it is empty, if it is empty, return false (cancelling form submission).</p>
<p>Now, there are a couple errors with the code above. For one, it is checking all form inputs (not just the one in our form), so if we had multiple forms on the page, both with required elements, this would fail. Also, being able to check more specific criteria would be nice. We will limit our iteration to input items that are of type text and are descendants of the target form. Let&#8217;s also add a maxlength attribute to a form field to ensure that it is within the set character length:</p>
<pre class="brush: jscript; title: Code Example; notranslate">
$(document).ready(function(){
	$('#login_form').submit(function(){
		var blank_fields = false;
		var length_error = false;//check for length errors
		$.each($('#login_form input[type=&quot;text&quot;]'), function(index, value){//limit input elements to those within the form
			var t = $(this);
			if(t.hasClass('required')){
				if(t.val() == &quot;&quot; || t.val() === undefined){//check if it's empty
					console.error('%s can not be blank', t.attr('name'));
					blank_fields = true;
				}
				if(t.attr('maxlength') !== undefined){//if maxlength attribute is present in the current element
					if(t.val().length &gt; t.attr('maxlength')){//check string length against given maxlength
						console.error('%s is too long: %i chars', t.attr('name'), t.val().length);
						length_error = true;
					}
				}
			}
		});
		return !(blank_fields || length_error);//if there are no blank fields and no length errors, submit
	});
});
</pre>
<p>Okay, now we are getting somewhere. This could be used as is, but it doesn&#8217;t provide very friendly error messages (they have to have Firebug installed to know what the errors are). Let&#8217;s wrap up our code so far into a jQuery function and provide some more useful errors. I&#8217;ve commented changes to the code, but it is mostly the same.</p>
<pre class="brush: jscript; title: Code Example; notranslate">
$.fn.validate = function(options){
	/*
	* Define the default error message tag and styling, allow this to be overridden
	*/
	var defaults = {
		 formTag: 'div',
		 color: '#8A1F11',
		 border: '2px solid #FBC2C4',
		 errorBG: '#FBE3E4 0 0',
		 marginBottom:'1em',
		 padding:'0.8em',
		 width: $(this).width()
	 };
	var o = $.extend(defaults, options);

	/*
	* Private method creates error element
	*/
	function genError(msg){
		var err = $(document.createElement(o.formTag));//create an error element
		err.css('border', 		 o.border)
		   .css('background', 	 o.errorBG)
		   .css('margin-bottom', o.marginBottom)
		   .css('padding', 		 o.padding)
		   .css('color', 		 o.color)
		   .css('width', 		 o.width);//Apply css style rules to the error
		err.html(msg);//insert the error message into the element
		return err;
	}

	/*
	* Our slightly modified form validation
	*/
	$(this).submit(function(){//now uses $(this) reference as the method is applied to the form selector
		var blank_fields = false;//initialize a generic error detector
		var length_error = false;
		//now we use $(this).find('input[type=&quot;text&quot;]') to locate our forms child elements
		$.each($(this).find('input[type=&quot;text&quot;]'), function(index, value){
			var t = $(this);
			if(t.hasClass('required')){
				if(t.val() == &quot;&quot; || t.val() === undefined){
					//instead of logging error, create a new element and append it to the input elements parent
					errormsg = genError(t.attr('name') + ' can not be blank')
					t.parent().append(errormsg);
					blank_fields = true;
				}
				if(t.attr('maxlength') !== undefined){
					if(t.val().length &gt; t.attr('maxlength')){
						//same as above but more concise
						t.parent().append(genError(t.attr('name') + ' is too long'));
						length_error = true;
					}
				}
			}
		});
		return !(blank_fields || length_error);
	});
}
</pre>
<p>Usage:</p>
<pre class="brush: jscript; title: Code Example; notranslate">
$(document).ready(function(){
	$('#login_form').validate({color:'#000'});
});
</pre>]]></content:encoded>
			<wfw:commentRss>http://www.bitconsultants.net/2008/jquery-form-validation-theory-and-practice/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using xcache
Page Caching using xcache
Object Caching 332/380 objects using memcached

Served from: www.bitconsultants.net @ 2012-02-05 15:34:26 -->
