<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Dylan&#039;s Blog</title>
	<atom:link href="http://gotdelta.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://gotdelta.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Mon, 02 Nov 2009 20:39:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='gotdelta.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Dylan&#039;s Blog</title>
		<link>http://gotdelta.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://gotdelta.wordpress.com/osd.xml" title="Dylan&#039;s Blog" />
	<atom:link rel='hub' href='http://gotdelta.wordpress.com/?pushpress=hub'/>
		<item>
		<title>jQuery: Basic Form Validation</title>
		<link>http://gotdelta.wordpress.com/2009/11/02/jquery-basic-form-validation/</link>
		<comments>http://gotdelta.wordpress.com/2009/11/02/jquery-basic-form-validation/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 20:38:11 +0000</pubDate>
		<dc:creator>gotdelta</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Form]]></category>
		<category><![CDATA[Input]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://gotdelta.wordpress.com/?p=59</guid>
		<description><![CDATA[Form validation, whether it be checking for empty fields or malicious code, is very important. While validation should also be done server-side, having an immediate response to errors can be a great usability booster. Thanks to jQuery, checking for empty fields in a form and notifying the user of them is very simple. This code [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gotdelta.wordpress.com&amp;blog=9588793&amp;post=59&amp;subd=gotdelta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Form validation, whether it be checking for empty fields or malicious code, is very important.  While validation should also be done server-side, having an immediate response to errors can be a great usability booster.  Thanks to jQuery, checking for empty fields in a form and notifying the user of them is very simple.</p>
<p>This code will be run where the user submits the form:<br />
<pre class="brush: jscript;">
$(function()
{
	$(&quot;.validate&quot;).submit(function()
	{
		validated = true;
		$(this).children(&quot;[type=text]&quot;).each(function()
		{
			$(this).removeClass(&quot;invalid&quot;);
			if ($(this).val() == &quot;&quot;)
			{
				validated = false;
				$(this).addClass(&quot;invalid&quot;);
			}
		});
		
		if (!validated)
		{
			alert(&quot;Please fix the highlighted errors.&quot;)
		}
		return validated;
	});
}
</pre></p>
<p>Before we loop through the text inputs in forms with class <code>validate</code>, we create a <code>validated</code> variable to keep track of the validation status.  Next, we loop through each of the text inputs contained in form.  In case there were errors from a previous submit, we remove the class <code>invalid</code>.  The <code>invalid</code> class (or whatever you want to name it) contains all the styling that will be added to inputs that are empty.  This could be a different background color or pretty much anything else.<br />
Next, we check to see if the text input is empty.  If it is, we set the <code>validated</code> variable to false and add the <code>invalid</code> class.  This is where you can run any additional code that you need for individual text inputs.<br />
After looping through all the text inputs, we check the <code>validated</code> variable to see if there were any entry fields.  If there were, an alert is opened up.  This is where you can put any other more useful code that you need to run for invalid forms.  Finally, we return <code>validated</code>.  If it is true (the form was validated) the form will be submitted without a hitch, but if it is false (the form was not validated) the form will not submit.</p>
<p>This is a good start, but it would be even better if users could have immediate feedback of errors:<br />
<pre class="brush: jscript;">
$(function()
{
	$(&quot;.validate input[type=text]&quot;).focus(function()
	{
		$(this).removeClass(&quot;invalid&quot;);
	}).blur(function()
	{
		if ($(this).val() == &quot;&quot;)
			$(this).addClass(&quot;invalid&quot;);
	});
});
</pre><br />
Similar to before, we loop through all of the text inputs in forms with the <code>validate</code> class.  When the user click in the form the <code>invalid</code> class is removed, in case they are going back to fix an error.  When they click out of the form, we check if the form is empty and if it is the <code>invalid</code> class is applied.</p>
<p>That&#8217;s all it takes for very basic form validation with jQuery!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gotdelta.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gotdelta.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gotdelta.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gotdelta.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gotdelta.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gotdelta.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gotdelta.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gotdelta.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gotdelta.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gotdelta.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gotdelta.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gotdelta.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gotdelta.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gotdelta.wordpress.com/59/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gotdelta.wordpress.com&amp;blog=9588793&amp;post=59&amp;subd=gotdelta&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gotdelta.wordpress.com/2009/11/02/jquery-basic-form-validation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48724ee92596b3d3ed33f142c930311f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gotdelta</media:title>
		</media:content>
	</item>
		<item>
		<title>jQuery: Default Text in Forms</title>
		<link>http://gotdelta.wordpress.com/2009/10/02/jquery-default-text-in-forms/</link>
		<comments>http://gotdelta.wordpress.com/2009/10/02/jquery-default-text-in-forms/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 21:55:27 +0000</pubDate>
		<dc:creator>gotdelta</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://gotdelta.wordpress.com/?p=52</guid>
		<description><![CDATA[To enhance the usability of your site, you&#8217;ll often want to give a form (a search box, for example) a default value. This is easily done thanks to the value HTML attribute. Once the user goes to use this form, however, you don&#8217;t want them to have to remove the default text. To get rid [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gotdelta.wordpress.com&amp;blog=9588793&amp;post=52&amp;subd=gotdelta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>To enhance the usability of your site, you&#8217;ll often want to give a form (a search box, for example) a default value. This is easily done thanks to the <code>value</code> HTML attribute.  Once the user goes to use this form, however, you don&#8217;t want them to have to remove the default text. To get rid of it automatically, we can use a bit of very simple jQuery.</p>
<p>We&#8217;ll be creating two functions that can be used together to create a fully functioning version of this feature. First, we&#8217;ll create the <code>listen_defaultText</code> function, which will create the callback functions that run when the user click into and out of the form.</p>
<p>The first question we need to ask is how we can store the default value of the form. The answer is that we don&#8217;t! The DOM contains a <code>defaultValue</code> property that contains the default text from the HTML <code>value</code> attribute. With this in mind, let&#8217;s create our function. Here it is in its entirety:<br />
<pre class="brush: jscript;">
function listen_defaultText(element)
{
	$(element).focus(function()
	{
		if ($(this).val() == $(this)[0].defaultValue)
		{
			$(this).val(&quot;&quot;);
			$(this).css(&quot;text-align&quot;, &quot;left&quot;);
		}
	}).blur(function()
	{
		if ($(this).val() == &quot;&quot;)
		{
			$(this).css(&quot;text-align&quot;, &quot;center&quot;);
			$(this).val($(this)[0].defaultValue);
		}
	});
}
</pre><br />
You can see that this function takes one argument &#8211; <code>element</code> &#8211; which will be the element or jQuery selector that you want the function to work on. The function adds a listener for the <code>onfocus</code> event, which will be run when the form is selected. Within the callback function for this event, you see <code>if ($(this).val() == $(this)[0].defaultValue)</code>. The tricky part of this is the right side of the comparison. <code>$(this)</code> refers to the jQuery object for element the function is being run for. A jQuery object is essentially a collection of DOM objects, and because an element on the page will only have one DOM object, we can access it with <code>$(this)[0]</code>. With this DOM object, it is easy to get any value you need &#8211; in our case we want the default value, which we get with <code>$(this)[0].defaultValue</code>.</p>
<p>If, when the user selects the form, the current value is the same as the default value we want to get rid of the text. We do this with <code>$(this).val("");</code>. You can also apply any styling you need here &#8211; in this case the default text is center aligned but any input is aligned left.</p>
<p>Next, we take advantage of jQuery&#8217;s event chaining to do what we need to when the user deselects the form. <code>}).blur(function()</code> adds a listener for the <code>onblur</code> event that is called when the previous <code>onfocus</code> event is finished. In this callback function for this, we check if the form is empty. If it is, the user hasn&#8217;t entered any text and we need to reset the styling and put the default text back. This is just the opposite of what we did in the focus event callback.</p>
<p>At this point, it may be important to note the order in which things are done in each callback function. For the focus event, if we changed the style before changing the value, slower machines might draw the default text aligned to the left before it can be removed. For the blur event, if we reset the value before resetting the CSS, slower machines might display the default text on the left before it can be re-centered. Hardly a major issue, but worth nothing nonetheless.</p>
<p>This function is now working just as we want it. However, there is still one problem that is not readily apparent. If the user has entered text and then refreshes the page, the browser will remember the text. After the refresh, however, this text will have the default style &#8211; in our case it will be centered instead of to the left. Also, if the user has clicked in the form, removing the default text, and refreshes the page, the default text will not be there afterwards. Both of these issues are relatively easy to resolve with another function we can create:<br />
<pre class="brush: jscript;">
function instantiate_defaultText(element)
{
	$(element).each(function()
	{
		if ($(this).val() != $(this)[0].defaultValue)
		{
			if ($(this).val() == &quot;&quot;)
			{
				$(this).val($(this)[0].defaultValue);
			}
			else
			{
				$(this).css(&quot;text-align&quot;, &quot;left&quot;);
			}
		}
	});
}
</pre></p>
<p>First, this function loops through all of the elements with <code>$(element).each(function()</code>. If the value of the form is not equal to the default value, another check is performed. If the form is empty &#8211; the second case I described &#8211; the form is reset back to it&#8217;s default value. We don&#8217;t need to worry about styling here because the default style of our forms is centered. Else, if the user has entered text that was carried over a refresh, we simply align it left.</p>
<p>To make use of these functions, we simply call them when the document is loaded:<br />
<pre class="brush: jscript;">
$(function() {
	instantiate_defaultText(&quot;.defaultText&quot;);
	listen_defaultText(&quot;.defaultText&quot;);
});
</pre><br />
The forms that need this functionality have the <code>defaultText</code> class, so that&#8217;s what we pass to each function.</p>
<p>And there you have it, user-friendly default text in forms.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gotdelta.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gotdelta.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gotdelta.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gotdelta.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gotdelta.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gotdelta.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gotdelta.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gotdelta.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gotdelta.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gotdelta.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gotdelta.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gotdelta.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gotdelta.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gotdelta.wordpress.com/52/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gotdelta.wordpress.com&amp;blog=9588793&amp;post=52&amp;subd=gotdelta&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gotdelta.wordpress.com/2009/10/02/jquery-default-text-in-forms/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48724ee92596b3d3ed33f142c930311f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gotdelta</media:title>
		</media:content>
	</item>
		<item>
		<title>Javascript: Capitalize Function</title>
		<link>http://gotdelta.wordpress.com/2009/10/02/javascript-capitalize-function/</link>
		<comments>http://gotdelta.wordpress.com/2009/10/02/javascript-capitalize-function/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 19:32:24 +0000</pubDate>
		<dc:creator>gotdelta</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://gotdelta.wordpress.com/?p=49</guid>
		<description><![CDATA[Here is a relatively simple javascript function to capitalize a word: Let&#8217;s go through this and see what exactly is going on. First, we see This is creating a new function called capitalize that takes one argument by the name of incomingString. Next, we see This takes a substring of the argument passed into our [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gotdelta.wordpress.com&amp;blog=9588793&amp;post=49&amp;subd=gotdelta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here is a relatively simple javascript function to capitalize a word:<br />
<pre class="brush: jscript;">
function capitalize(incomingString) {
	var letter = incomingString.substr(0,1);

	var str = incomingString.toLowerCase();

	return letter.toUpperCase() + str.substr(1);
}
</pre></p>
<p>Let&#8217;s go through this and see what exactly is going on. First, we see<br />
<pre class="brush: jscript;">function capitalize(incomingString) {</pre><br />
This is creating a new function called <code>capitalize</code> that takes one argument by the name of <code>incomingString</code>.</p>
<p>Next, we see<br />
<pre class="brush: jscript;">var letter = incomingString.substr(0,1);</pre><br />
This takes a substring of the argument passed into our function. A substring is simply a part of a string, in this case from the first character (0) to 1 more than than the character at 0, non-inclusive. This substring &#8211; which is the first character in the string &#8211; is then stored in a new variable called <code>letter</code>.</p>
<p>The next line is<br />
<pre class="brush: jscript;">var str = incomingString.toLowerCase();</pre><br />
This code is completely self-explanatory. It creates a new variable called <code>str</code> that contains an all-lowercase version of the input string.</p>
<p>The last part of the function is<br />
<pre class="brush: jscript;">return letter.toUpperCase() + str.substr(1);</pre><br />
This creates a concatenated string with an uppercase version of the first letter that we extracted earlier and a substring of the lowercase string from 1 to the end of the string. This capitalized string is then returned from the function.</p>
<p>This function is more complex than it needs to be, however. We can achieve the exact same functionality with this:<br />
<pre class="brush: jscript;">
function capitalize(incomingString)
{
	return incomingString.charAt(0).toUpperCase() + incomingString.substring(1).toLowerCase();
}
</pre><br />
This function is both shorter and more direct. We use <code>charAt()</code> (I think you can figure out what it does) to get the first character and <code>substring()</code> to get the rest of the string. <code>substring()</code> is an alternative to <code>substr</code> that in this case works in the same way.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gotdelta.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gotdelta.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gotdelta.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gotdelta.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gotdelta.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gotdelta.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gotdelta.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gotdelta.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gotdelta.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gotdelta.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gotdelta.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gotdelta.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gotdelta.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gotdelta.wordpress.com/49/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gotdelta.wordpress.com&amp;blog=9588793&amp;post=49&amp;subd=gotdelta&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gotdelta.wordpress.com/2009/10/02/javascript-capitalize-function/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48724ee92596b3d3ed33f142c930311f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gotdelta</media:title>
		</media:content>
	</item>
		<item>
		<title>Tabbed Horizontal Navigation with Unordered Lists</title>
		<link>http://gotdelta.wordpress.com/2009/09/29/tabbed-horizontal-navigation-with-unordered-lists/</link>
		<comments>http://gotdelta.wordpress.com/2009/09/29/tabbed-horizontal-navigation-with-unordered-lists/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 12:04:44 +0000</pubDate>
		<dc:creator>gotdelta</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://gotdelta.wordpress.com/?p=30</guid>
		<description><![CDATA[There are numerous possible ways to make a horizontal navigation bar for your website, but the cleanest and perhaps the most sensible way is with an unordered list. We&#8217;ll be making a simple tabbed navigation bar using only an unordered list and some CSS. We&#8217;ll start with a simple list with links, contained within a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gotdelta.wordpress.com&amp;blog=9588793&amp;post=30&amp;subd=gotdelta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There are numerous possible ways to make a horizontal navigation bar for your website, but the cleanest and perhaps the most sensible way is with an unordered list.  We&#8217;ll be making a simple tabbed navigation bar using only an unordered list and some CSS.</p>
<p>We&#8217;ll start with a simple list with links, contained within a div:<br />
<pre class="brush: xml;">
&lt;div id=&quot;navigation&quot;&gt;
	&lt;ul class=&quot;navbar&quot;&gt;
		&lt;li&gt;&lt;a href=&quot;#1&quot;&gt;One&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#2&quot; class=&quot;active&quot;&gt;Two&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#3&quot;&gt;Three&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#47&quot;&gt;Forty Two Thousand&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/div&gt;
</pre><br />
Which looks like this:<br />
<img class="alignnone size-full wp-image-31" src="http://gotdelta.files.wordpress.com/2009/09/1.png?w=600" alt=""   /></p>
<p>Now let&#8217;s add some CSS. First, we&#8217;ll reset all padding and margins:<br />
<pre class="brush: css;">
* {
	margin: 0;
	padding: 0;
}
</pre></p>
<p>And then add some initial styling:<br />
<pre class="brush: css;">
body {
	background-color: #CCC;
}

#navigation {
	height: 50px;
	
	background-color: #777;
	border-bottom: 1px solid #000;
}
</pre><br />
Our page now looks like this:<br />
<img src="http://gotdelta.files.wordpress.com/2009/09/2.png?w=600" alt="" title=""   class="alignnone size-full wp-image-34" /></p>
<p>Not quite what we&#8217;re looking for.</p>
<p>Next, we&#8217;ll start adding the CSS for the ul:<br />
<pre class="brush: css;">
.navbar {
	margin-left: 10px;
	list-style: none;
}
</pre><br />
<code>list-style: none;</code> removes the bullet points from the list. Although you couldn&#8217;t see them after the previous step, they were still there. The reset margins simply caused them to draw outside of the screen.</p>
<p>Now we&#8217;ll add the CSS that actually makes the list horizontal:<br />
<pre class="brush: css;">
.navbar li {
	float: left;
	margin-left: 10px;
}
</pre><br />
Yup, <code>float: left;</code> is all you need to make the list horizontal. <code>margin-left: 10px;</code> simply adds some much needed spacing.</p>
<p>Our navigation bar is finally starting to look like a navigation bar:<br />
<img src="http://gotdelta.files.wordpress.com/2009/09/3.png?w=600" alt="" title=""   class="alignnone size-full wp-image-38" /></p>
<p>The bulk of the visual styling is done on the <code>a</code> tags:<br />
<pre class="brush: css;">
.navbar li a {
	padding: 0 40px;
	
	background-color: #99CCFF;
	border: 1px solid #000;
	border-bottom: none;
}
.navbar li a:hover {
	background-color: #6699CC;
}
.navbar li a:active {
	background-color: #336699;
}</pre><br />
This is mostly self-explanatory. We added 40px of space to either side of the text in the <code>a</code> with <code>padding: 0 40px;</code>. We removed the bottom border for a good reason, as you&#8217;ll see in a few seconds. This is the current state of our navigation bar:<br />
<img src="http://gotdelta.files.wordpress.com/2009/09/4.png?w=600&#038;h=80" alt="4" title="4" width="600" height="80" class="alignnone size-full wp-image-40" /></p>
<p>We&#8217;re almost there! Now we push the tabs down a bit by adding some padding to each <code>li</code>:<br />
<pre class="brush: css;">
.navbar li {
	float: left;
	margin-left: 10px;
	padding-top: 20px;
}
</pre><br />
Giving us this:<br />
<img src="http://gotdelta.files.wordpress.com/2009/09/5.png?w=600&#038;h=63" alt="5" title="5" width="600" height="63" class="alignnone size-full wp-image-42" /></p>
<p>And finally, we add <code>line-height: 29px;</code> to <code>#navigation</code>:<br />
<pre class="brush: css;">
#navigation {
	height: 50px;
	line-height: 29px;
	
	background-color: #777;
	border-bottom: 1px solid #000;
}
</pre><br />
&#8230; and <code>display: block;</code> to <code>.navbar li a</code>:<br />
<pre class="brush: css;">
.navbar li a {
	display: block;
	
	padding: 0 40px;
	
	background-color: #99CCFF;
	border: 1px solid #000;
	border-bottom: none;
}
</pre><br />
&#8230; giving us a final result of:<br />
<img src="http://gotdelta.files.wordpress.com/2009/09/61.png?w=600&#038;h=78" alt="6" title="6" width="600" height="78" class="alignnone size-full wp-image-44" /></p>
<p>At this point we can add some styling to the <code>active</code> class to show which tab is currently active. We&#8217;ll make the tab appear to be en extension of the page:<br />
<pre class="brush: css;">
.navbar li a.active {
	background-color: #CCC;
	border-bottom: 1px solid #CCC;
}
</pre><br />
<img src="http://gotdelta.files.wordpress.com/2009/09/7.png?w=600&#038;h=81" alt="7" title="7" width="600" height="81" class="alignnone size-full wp-image-45" /></p>
<p>At this point it should be easy to style the tabs as you need.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gotdelta.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gotdelta.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gotdelta.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gotdelta.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gotdelta.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gotdelta.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gotdelta.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gotdelta.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gotdelta.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gotdelta.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gotdelta.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gotdelta.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gotdelta.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gotdelta.wordpress.com/30/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gotdelta.wordpress.com&amp;blog=9588793&amp;post=30&amp;subd=gotdelta&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gotdelta.wordpress.com/2009/09/29/tabbed-horizontal-navigation-with-unordered-lists/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48724ee92596b3d3ed33f142c930311f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gotdelta</media:title>
		</media:content>

		<media:content url="http://gotdelta.files.wordpress.com/2009/09/1.png" medium="image" />

		<media:content url="http://gotdelta.files.wordpress.com/2009/09/2.png" medium="image" />

		<media:content url="http://gotdelta.files.wordpress.com/2009/09/3.png" medium="image" />

		<media:content url="http://gotdelta.files.wordpress.com/2009/09/4.png" medium="image">
			<media:title type="html">4</media:title>
		</media:content>

		<media:content url="http://gotdelta.files.wordpress.com/2009/09/5.png" medium="image">
			<media:title type="html">5</media:title>
		</media:content>

		<media:content url="http://gotdelta.files.wordpress.com/2009/09/61.png" medium="image">
			<media:title type="html">6</media:title>
		</media:content>

		<media:content url="http://gotdelta.files.wordpress.com/2009/09/7.png" medium="image">
			<media:title type="html">7</media:title>
		</media:content>
	</item>
		<item>
		<title>Parsing XML With jQuery</title>
		<link>http://gotdelta.wordpress.com/2009/09/24/parsing-xml-with-jquery/</link>
		<comments>http://gotdelta.wordpress.com/2009/09/24/parsing-xml-with-jquery/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 20:48:20 +0000</pubDate>
		<dc:creator>gotdelta</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Parsing]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://gotdelta.wordpress.com/?p=7</guid>
		<description><![CDATA[The XML file (bluetooth.xml) we&#8217;ll be working with looks something like this: We&#8217;re going to parse through this file and return the value of an attribute for all of a certain tag. To allow the user the input the tag and its attribute that they want, we&#8217;ll need a form: The form needs an id, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gotdelta.wordpress.com&amp;blog=9588793&amp;post=7&amp;subd=gotdelta&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The XML file (bluetooth.xml) we&#8217;ll be working with looks something like this:</p>
<p><pre class="brush: xml;">
&lt;bluetooth&gt;
&lt;provider id=&quot;4&quot; name=&quot;AllTel&quot;&gt;
&lt;manufacturer name=&quot;AudioVox (UTSmartComm)&quot;&gt;
&lt;phone name=&quot;ppc6700&quot;&gt;
&lt;cat id=&quot;1&quot; data=&quot;Supported&quot;&gt;&lt;/cat&gt;
&lt;cat id=&quot;2&quot; data=&quot;Not Supported&quot;&gt;&lt;/cat&gt;
&lt;/phone&gt;
&lt;/manufacturer&gt;
&lt;/provider&gt;
</pre></p>
<p>We&#8217;re going to parse through this file and return the value of an attribute for all of a certain tag.</p>
<p>To allow the user the input the tag and its attribute that they want, we&#8217;ll need a form:</p>
<p><pre class="brush: xml;">
&lt;form id=&quot;search&quot;&gt;
&lt;label for=&quot;nodeInput&quot;&gt;Tag:&lt;/label&gt;&lt;input type=&quot;text&quot; id=&quot;tagInput&quot; /&gt;&lt;br /&gt;
&lt;label for=&quot;attrInput&quot;&gt;Attribute:&lt;/label&gt;&lt;input type=&quot;text&quot; id=&quot;attrInput&quot; /&gt;&lt;br /&gt;
&lt;input type=&quot;submit&quot; value=&quot;Search&quot;&gt;
&lt;/form&gt;
</pre></p>
<p>The form needs an id, and if you want to verify the input you should give ids to the two text inputs as well.</p>
<p>Thanks to jQuery, the Javascript for parsing the XML according to the input is surprisingly simple. Here it is in its entirety:</p>
<p><pre class="brush: jscript;">
var doc = &quot;bluetooth.xml&quot;;

$(function()
{
$(&quot;#search&quot;).submit(function()
{
if ($(&quot;#tagInput&quot;).val() != '' &amp;&amp; $(&quot;#attrInput&quot;).val() != '')
{
$.get(doc, {}, function(xml)
{
var results = &quot;&quot;;

$($(&quot;#tagInput&quot;).val(), xml).each(function()
{
results += $(this).attr($(&quot;#attrInput&quot;).val()) + &quot;&lt;br /&gt;&quot;;
});

$(&quot;#searchResults&quot;).html(results);
});
}

return false;
});
});
</pre></p>
<p>The first thing you&#8217;ll notice while reading this is that the <code>$();</code> function is used <em>a lot</em>. It is shorthand for <code>jQuery();</code> and has a wealth of functionality. The first time we use this function, a single anonymous function is passed as its parameter. This is shorthand for <code>$(document).ready(function() {...} );</code>. Whichever way you decide to write it, it will cause the function to be called when the DOM of the page is loaded. The first thing within this function is <code>$("#search").submit(function()</code>. This is saying to run the given function (which is known as an event handler, in this context) when the submit event is triggered for the element with id <code>search</code>. We&#8217;re aren&#8217;t going to parse any XML until the user submits the form, and when that happens this function will run.</p>
<p>The first thing we need to do when the user submits the form is check that they&#8217;ve actually filled it out. We can get the string that is currently in a text box with <code>$("#textboxid").val()</code>, and to check if it&#8217;s empty we simply test if it is equal to an empty string.</p>
<p>Next, the usefulness of jQuery is put on display when we retrieve the XML document: <code>$.get(doc, {}, function(xml) {...} );</code>. This seemingly simple piece of code is a complete AJAX request. <code>$.get();</code> takes three parameters: the URL, data that will get sent to the server, and a callback function. We don&#8217;t need to send any data, so the second parameter is simply <code>{}</code>. The callback function is created as <code>function(xml)</code>, which allows us to access the data the request returned through the object named <code>xml</code>.</p>
<p>Now that we have the XML document, we can finally do some parsing. The search results will be output to a div below the form. The html that will be generated while parsing will be stored in the <code>results</code> string until we can output it to the div.</p>
<p>The next line &#8211; <code>$($("#tagInput").val(), xml).each(function()</code> &#8211; searches for all of the given tag (the value of the tag input box) in the xml document and iterates through all of them, executing the anonymous function every time.</p>
<p>We get the attribute with <code>$(this).attr($("#attrInput").val())</code>. In this context, <code>this</code> refers to an xml tag that matched our search criteria. The <code>.attr()</code> method takes the name of an attribute (in this case what the user entered) and returns its value. It is appended to the <code>results</code> string with a <code>&lt;br /&gt;</code>.</p>
<p>After the <code>results</code> string is compiled, we put it in the div: <code>$("#searchResults").html(results);</code></p>
<p>All that&#8217;s left is <code>return false;</code>. This makes it so that the page doesn&#8217;t refresh when the form is submitted.</p>
<p>All said and done, this is what it looks like:<br />
<img src="http://gotdelta.files.wordpress.com/2009/09/searchresults.png?w=600" alt="Search Results" title="searchResults"   class="size-full wp-image-25" /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gotdelta.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gotdelta.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gotdelta.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gotdelta.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gotdelta.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gotdelta.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gotdelta.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gotdelta.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gotdelta.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gotdelta.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gotdelta.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gotdelta.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gotdelta.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gotdelta.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gotdelta.wordpress.com&amp;blog=9588793&amp;post=7&amp;subd=gotdelta&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gotdelta.wordpress.com/2009/09/24/parsing-xml-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48724ee92596b3d3ed33f142c930311f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gotdelta</media:title>
		</media:content>

		<media:content url="http://gotdelta.files.wordpress.com/2009/09/searchresults.png" medium="image">
			<media:title type="html">searchResults</media:title>
		</media:content>
	</item>
	</channel>
</rss>
