<?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>Design Chemical - jQuery, Wordpress, Tutorials &#38; Plugins&#187; Website Coding</title>
	<atom:link href="http://www.designchemical.com/blog/index.php/category/website-coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.designchemical.com/blog</link>
	<description>Your Business Catalyst</description>
	<lastBuildDate>Sun, 22 Jan 2012 12:55:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>jQuery Tutorial &#8211; Create a Flexible Data Heat Map</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/jquery-tutorial-create-a-flexible-data-heat-map/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/jquery-tutorial-create-a-flexible-data-heat-map/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 03:01:52 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=2498</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/jquery-tutorial-create-a-flexible-data-heat-map/"><img align="left" hspace="5" width="150" src="/media/images/jquery_data_heat_map.png" class="alignleft wp-post-image tfe" alt="jQuery Data Heat Map" title="" /></a><p class="text-center"><img src="/media/images/jquery_data_heat_map.png" alt="jQuery Data Heat Map" class="img-border" /></p>
<p>Add more excitement to data tables using jQuery and conditional formatting to generate flexible data &#8220;heat maps&#8221;.</p>
<p>Long tables of numbers are never fun to look at and when presenting this kind of data on the web, where attention spans are already at their limits, you need to be able to present the highlights as quickly as possible. &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/jquery-tutorial-create-a-flexible-data-heat-map/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p class="text-center"><img src="/media/images/jquery_data_heat_map.png" alt="jQuery Data Heat Map" class="img-border" /></p>
<p>Add more excitement to data tables using jQuery and conditional formatting to generate flexible data &#8220;heat maps&#8221;.</p>
<p>Long tables of numbers are never fun to look at and when presenting this kind of data on the web, where attention spans are already at their limits, you need to be able to present the highlights as quickly as possible.</p>
<p>Data heat maps provide the perfect way of taking ordinary data and creating something more visually appealing and informative.</p>
<p><a href="/lab/jquery/demo/jquery_data_heat_map_demo.htm">jQuery Data Heat Map Demo</a></p>
<p><a href="/lab/jquery/demo/download/jquery-data-heat-map.zip">Download tutorial source files</a></p>
<h3>Tutorial Objectives</h3>
<p>To create our heat map in a way that is flexible enough to cover any range of values, there are several key components to our jQuery code that we need to consider:</p>
<ul class="content-list">
<li>Capture and statistically analyze all data points</li>
<li>Have a method of then grouping the data and being able to identify what formatting should be applied</li>
<li>Dynamically generate the CSS to be used for each group to create a heat map style effect</li>
<li>Apply the correct CSS to each data point</li>
</ul>
<p>For this tutorial we will be using a random table of numbers and the formatting will be applied based on each value as a % of the largest value.</p>
<h3>The Basic HTML</h3>
<p>The complete table can be found on the <a href="/lab/jquery/demo/jquery_data_heat_map_demo.htm">demo page</a>. The HTML below gives the basic table structure, showing one row of data and the CSS classes we will be using:</p>
<pre class="brush: php; title: ; notranslate">
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; border=&quot;0&quot; class=&quot;heat-map&quot;&gt;
    &lt;thead&gt;
        &lt;tr&gt;
		    &lt;th class=&quot;first&quot;&gt;Title&lt;/th&gt;
			&lt;th&gt;data 1&lt;/th&gt;
			&lt;th&gt;data 2&lt;/th&gt;
			&lt;th&gt;data 3&lt;/th&gt;
			&lt;th&gt;data 4&lt;/th&gt;
			&lt;th&gt;data 5&lt;/th&gt;
			&lt;th class=&quot;last&quot;&gt;data 6&lt;/th&gt;
		&lt;/tr&gt;
    &lt;/thead&gt;
	&lt;tbody&gt;
	    &lt;tr class=&quot;stats-row&quot;&gt;
		    &lt;td class=&quot;stats-title&quot;&gt;Wanda&lt;/td&gt;
			&lt;td&gt;25&lt;/td&gt;
			&lt;td&gt;55&lt;/td&gt;
			&lt;td&gt;26&lt;/td&gt;
			&lt;td&gt;19&lt;/td&gt;
			&lt;td&gt;39&lt;/td&gt;
			&lt;td&gt;21&lt;/td&gt;
		&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
</pre>
<div class="clear banner-horizontal">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-7740611438413740";
/* Banner Mid Post */
google_ad_slot = "8625321051";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<h3>The jQuery Code</h3>
<h4>1. Capture and analyze the data</h4>
<p>The first thing we need to do is find out the largest value within the data range. To do this we use fairly simple but useful code to create an array of all data points and then return the maximum value:</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/JavaScript&quot;&gt;
$(document).ready(function(){

	// Function to get the max value in an Array
    Array.max = function(array){
        return Math.max.apply(Math,array);
    };

	// Get all data values from our table cells making sure to ignore the first column of text
	// Use the parseInt function to convert the text string to a number

    var counts= $('.heat-map tbody td').not('.stats-title').map(function() {
        return parseInt($(this).text());
    }).get();

	// run max value function and store in variable
	var max = Array.max(counts);

});
&lt;/script&gt;
</pre>
<h4>2. Group data points</h4>
<p>For this tutorial we have already decided that we will use % of each value from max value. We do this so that we can find exactly where the data point is positioned on a scale of 1 &#8211; 100. This is the critical part in creating the heat map as we will then use this scale to dynamically generate the CSS styles</p>
<p>100 is probably a little excessive but is an easy number to work with for the tutorial. You can obviously adjust this number to suit your data and style of heat map.</p>
<p>We only want to use integers so we also include some additional rounding of the results</p>
<pre class="brush: jscript; title: ; notranslate">

n = 100; // Declare the number of groups

// Loop through each data point and calculate its % value
$('.heat-map tbody td').not('.stats-title').each(function(){
	var val = parseInt($(this).text());
	var pos = parseInt((Math.round((val/max)*100)).toFixed(0));
});
</pre>
<p>The above code is not yet complete since we will add the actual formatting into the same loop but have broken it down to explain how we create each step.</p>
<h4>3. Dynamically generating the heat map styles</h4>
<p>To create the heat map effect we are basically going to use background colour.</p>
<p>Technically there is no restriction on how you apply the styles and background colour is only one option. The code is fairly flexible and with some minor adjustments can be applied to font size, container size, background image, etc.</p>
<p>Colour is easy because we can directly calculate each colour value between 2 defined colours &#8211; our start point and the end point, which across 100 points should create a gradient style effect.</p>
<p>To calculate colour we need to use the RGB values, which are 0 to 255 for Red, Blue and Green.</p>
<pre class="brush: jscript; title: ; notranslate">

// Define the ending colour, which is white
   xr = 255; // Red value
   xg = 255; // Green value
   xb = 255; // Blue value

// Define the starting colour #f32075
   yr = 243; // Red value
   yg = 32; // Green value
   yb = 117; // Blue value

// Calculate a specific colour point
// pos - calculated in the earlier code identifies where on the scale the data point is

red = parseInt((xr + (( pos * (yr - xr)) / (n-1))).toFixed(0));
green = parseInt((xg + (( pos * (yg - xg)) / (n-1))).toFixed(0));
blue = parseInt((xb + (( pos * (yb - xb)) / (n-1))).toFixed(0));

// Once we have our RGB values we combine them to create our CSS code
clr = 'rgb('+red+','+green+','+blue+')';
</pre>
<h4>4. Apply the heat map styles to each data point</h4>
<p>Finally we apply the new RGB value by setting the background colour of the table cell.</p>
<pre class="brush: jscript; title: ; notranslate">

$(this).css({backgroundColor:clr});
</pre>
<p>We combine steps 2, 3 &#038; 4 so that this is all being carried out within the same loop.</p>
<h3>The Complete jQuery Code</h3>
<p>The code below shows all 4 steps combined to create the complete heat map function:</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/JavaScript&quot;&gt;
$(document).ready(function(){

	// Function to get the max value in an Array
    Array.max = function(array){
        return Math.max.apply(Math,array);
    };

	// Get all data values from our table cells making sure to ignore the first column of text
	// Use the parseInt function to convert the text string to a number

    var counts= $('.heat-map tbody td').not('.stats-title').map(function() {
        return parseInt($(this).text());
    }).get();

	// run max value function and store in variable
	var max = Array.max(counts);

	n = 100; // Declare the number of groups

    // Define the ending colour, which is white
    xr = 255; // Red value
    xg = 255; // Green value
    xb = 255; // Blue value

    // Define the starting colour #f32075
    yr = 243; // Red value
    yg = 32; // Green value
    yb = 117; // Blue value

    // Loop through each data point and calculate its % value
    $('.heat-map tbody td').not('.stats-title').each(function(){
	    var val = parseInt($(this).text());
	    var pos = parseInt((Math.round((val/max)*100)).toFixed(0));
		red = parseInt((xr + (( pos * (yr - xr)) / (n-1))).toFixed(0));
		green = parseInt((xg + (( pos * (yg - xg)) / (n-1))).toFixed(0));
		blue = parseInt((xb + (( pos * (yb - xb)) / (n-1))).toFixed(0));
		clr = 'rgb('+red+','+green+','+blue+')';
    });
});
&lt;/script&gt;
</pre>
<p>To completely change the look of the heat map all it requires is to change the start colour and end colour RGB values!</p>
<p>Check out the demo page for more examples &#8211; <a href="/lab/jquery/demo/jquery_data_heat_map_demo.htm">jQuery Data Heat Map Demo</a> or <a href="/lab/jquery/demo/download/jquery-data-heat-map.zip">Download the tutorial source files</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/jquery-tutorial-create-a-flexible-data-heat-map/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>jQuery Tutorial &#8211; Create a jQuery Menu Slider</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/jquery-tutorial-create-a-jquery-menu-slider/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/jquery-tutorial-create-a-jquery-menu-slider/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 05:32:46 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[slider]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=2140</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/jquery-tutorial-create-a-jquery-menu-slider/"><img align="left" hspace="5" width="150" src="/media/images/jquery_menu_slider.png" class="alignleft wp-post-image tfe" alt="jQuery Menu Slider" title="" /></a><p class="text-center pad-top"><img src="/media/images/jquery_menu_slider.png" alt="jQuery Menu Slider" /></p>
<p>In the following tutorial we are going to go through how to create a jQuery menu slider similar to the one used in our own website&#8217;s mega menu navigation (see &#8220;WordPress Plugins&#8221; menu item).</p>
<p class="clear"><span>View Demo</span> <span>Download Source Code</span></p>
The HTML
<p>The HTML is very simple and basically includes:</p>
<ul class="content-list">
<li>A wrapper (&#8220;#menu-slider&#8221;) &#8211; only</li></ul><p> &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/jquery-tutorial-create-a-jquery-menu-slider/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p class="text-center pad-top"><img src="/media/images/jquery_menu_slider.png" alt="jQuery Menu Slider" /></p>
<p>In the following tutorial we are going to go through how to create a jQuery menu slider similar to the one used in our own website&#8217;s mega menu navigation (see &#8220;WordPress Plugins&#8221; menu item).</p>
<p class="clear"><a href="/lab/jquery/demo/jquery_demo_create_jquery_menu_slider.htm" class="demo"><span>View Demo</span></a> <a href="/lab/jquery/demo/download/jquery-menu-slider.zip" class="demo"><span>Download Source Code</span></a></p>
<h3 class="clear">The HTML</h3>
<p>The HTML is very simple and basically includes:</p>
<ul class="content-list">
<li>A wrapper (&#8220;#menu-slider&#8221;) &#8211; only used for styling the jquery menu slider</li>
<li>An unordered list of text links (&#8220;#list-links&#8221;), which will make up the menu section</li>
<li>A list of images (&#8220;#list-images&#8221;) including captions, which will be used to create the slider</li>
</ul>
<pre class="brush: php; title: ; notranslate">
&lt;div id=&quot;menu-slider&quot;&gt;
    &lt;ul id=&quot;list-links&quot;&gt;
        &lt;li class=&quot;hover&quot;&gt;&lt;a href=&quot;/blog/index.php/wordpress-plugins/wordpress-plugin-jquery-drop-down-mega-menu-widget/&quot;&gt;Mega Menu&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;/blog/index.php/wordpress-plugins/wordpress-plugin-jquery-vertical-mega-menu-widget/&quot;&gt;Vertical Mega Menu&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;/blog/index.php/wordpress-plugins/wordpress-plugin-jquery-vertical-accordion-menu-widget/&quot;&gt;Vertical Accordion Menu&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;/blog/index.php/wordpress-plugins/wordpress-plugin-jquery-drill-down-ipod-menu-widget/&quot;&gt;jQuery Drill Down iPod Menu&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;/blog/index.php/wordpress-plugins/wordpress-plugin-jquery-slick-menu-widget/&quot;&gt;jQuery Slick Menu&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;/blog/index.php/wordpress-plugins/wordpress-plugin-jquery-floating-menu/&quot;&gt;Floating Menu&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;/blog/index.php/wordpress-plugins/wordpress-plugin-floating-tweets/&quot;&gt;Floating Tweets&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;/blog/index.php/wordpress-plugin-slick-contact-forms/&quot;&gt;Slick Contact Forms&lt;/a&gt;&lt;/li&gt;
        &lt;li class=&quot;last&quot;&gt;&lt;a href=&quot;/blog/index.php/wordpress-plugins/wordpress-plugin-slick-social-share-buttons/&quot;&gt;Slick Social Share Buttons&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;

    &lt;ul id=&quot;list-images&quot;&gt;
        &lt;li&gt;&lt;a href=&quot;/blog/index.php/wordpress-plugins/wordpress-plugin-jquery-drop-down-mega-menu-widget/&quot;&gt;
            &lt;img src=&quot;/media/images/mega_1a.jpg&quot; alt=&quot;&quot; /&gt;
            &lt;span&gt;jQuery Horizontal Mega Menu&lt;/span&gt;&lt;/a&gt;
        &lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;/blog/index.php/wordpress-plugins/wordpress-plugin-jquery-vertical-mega-menu-widget/&quot;&gt;
            &lt;img src=&quot;/media/images/mega_2a.jpg&quot; alt=&quot;&quot; /&gt;
            &lt;span&gt;jQuery Vertical Mega Menu&lt;/span&gt;&lt;/a&gt;
        &lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;/blog/index.php/wordpress-plugins/wordpress-plugin-jquery-vertical-accordion-menu-widget/&quot;&gt;
            &lt;img src=&quot;/media/images/mega_3a.jpg&quot; alt=&quot;&quot; /&gt;
            &lt;span&gt;jQuery Vertical Accordion Menu&lt;/span&gt;&lt;/a&gt;
        &lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;/blog/index.php/wordpress-plugins/wordpress-plugin-jquery-drill-down-ipod-menu-widget/&quot;&gt;
            &lt;img src=&quot;/media/images/mega_4a.jpg&quot; alt=&quot;&quot; /&gt;
            &lt;span&gt;jQuery Drill Down iPod Menu&lt;/span&gt;&lt;/a&gt;
        &lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;/blog/index.php/wordpress-plugins/wordpress-plugin-jquery-slick-menu-widget/&quot;&gt;
            &lt;img src=&quot;/media/images/mega_5a.jpg&quot; alt=&quot;&quot; /&gt;
            &lt;span&gt;jQuery Slick Menu&lt;/span&gt;&lt;/a&gt;
        &lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;/blog/index.php/wordpress-plugins/wordpress-plugin-jquery-floating-menu/&quot;&gt;
            &lt;img src=&quot;/media/images/mega_6a.png&quot; alt=&quot;&quot; /&gt;
            &lt;span&gt;Floating Menu Widget&lt;/span&gt;&lt;/a&gt;
        &lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;/blog/index.php/wordpress-plugins/wordpress-plugin-floating-tweets/&quot;&gt;
            &lt;img src=&quot;/media/images/mega_7a.png&quot; alt=&quot;&quot; /&gt;
            &lt;span&gt;Floating Tweets Widget&lt;/span&gt;&lt;/a&gt;
        &lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;/blog/index.php/wordpress-plugin-slick-contact-forms/&quot;&gt;
            &lt;img src=&quot;/media/images/mega_8a.jpg&quot; alt=&quot;&quot; /&gt;
            &lt;span&gt;Slick Contact Forms&lt;/span&gt;&lt;/a&gt;
        &lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;/blog/index.php/wordpress-plugins/wordpress-plugin-slick-social-share-buttons/&quot;&gt;
            &lt;img src=&quot;/media/images/mega_9a.jpg&quot; alt=&quot;&quot; /&gt;
            &lt;span&gt;Slick Social Share Buttons&lt;/span&gt;&lt;/a&gt;
        &lt;/li&gt;
    &lt;/ul&gt;
    &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>On the first link we have added the class &#8220;hover&#8221; to show the active state for the slider when the page loads.</p>
<div class="banner-horizontal">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-7740611438413740";
/* Banner Mid Post */
google_ad_slot = "8625321051";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<h3>The Slider jQuery Code</h3>
<p>The jQuery is surprisingly simple for the menu slider. Basically it involves 2 parts &#8211; creating the slider structure and then the function to handle the hover event when hovering over the list of links:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function() {

    // Declare variables
    var width = 400; // width of slide - required for animation calculation
    var slides = $('#list-images li');
    var numSlides = slides.length;

    // Wrap the slides &amp; set the wrap width - this will be used to animate the slider left/right
    slides.wrapAll('&lt;div id=&quot;slide-wrap&quot;&gt;&lt;/div&gt;').css({'float' : 'left','width' : width});
    $('#slide-wrap').css({width: width * numSlides});

    // Hover function - animate the slides based on index of active link
    $('#list-links li a').hover(function(){
        $('#list-links li').removeClass('hover');
        var i = $(this).index('#list-links li a');
        $(this).parent().addClass('hover');
        $('#slide-wrap').stop().animate({'marginLeft' : width*(-i)});
    });
});
</pre>
<p>In the above code we wrap the sliders in a div tag (&#8220;#slide-wrap&#8221;) &#8211; this is what is actually animated to give the sliding effect when hovering over a menu item.</p>
<p>The hover function on the list of links calculates how far to animate the slide-wrap based on the width of the slide and the index number of the active link. The function also adds class &#8220;hover&#8221; to the active li tag, which we can use to style the menu to indicate the active menu item.</p>
<h3>The Menu Slider CSS</h3>
<p>Finally some CSS styles to create the required design:</p>
<pre class="brush: plain; title: ; notranslate">
#menu-slider {
background: url(images/bg_menu_slider.png) no-repeat 0 0;
padding: 15px;
margin-bottom: 20px;
}

/* Required */
#list-images, #list-images li {
height: 292px;
width: 400px;
display: block;
}
#list-images {
float: right;
overflow: hidden; /* Required to hide the inactive slides */
border: 1px solid #ccc;
}
#list-images li {
position: relative;
}

#list-images li img {
background: #fff;
position: absolute;
top: 0;
left: 0;
}

/* Image captions */
#list-images li span {
background: url(images/grid1.png) repeat 0 0;
position: absolute;
bottom: 0;
left: 0;
width: 362px;
display: block;
padding: 14px 20px;
font: bold 20px Arial, sans-serif;
color: #fff;
height: 20px;
line-height: 20px;
}

/* Menu text links */
#list-links {
width: 220px;
float: left;
}
#list-links li {
padding: 0 15px 0 0;
}
#list-links li a {
font: normal 12px Arial, sans-serif;
color: #222;
padding: 8px 5px 8px 8px;
border-bottom: 1px solid #ccc;
font-weight: bold;
font-size: 13px;
display: block;
}
#list-links li.hover {
background: url(images/tab_current.png) no-repeat 100% center;
}
#list-links li.hover a, #list-links li.hover a:hover {
color: #fff;
background: none;
border-bottom: none;
padding-bottom: 9px;
}
#list-links li.last a {
border-bottom: none;
}
</pre>
<p class="clear"><a href="/lab/jquery/demo/jquery_demo_create_jquery_menu_slider.htm" class="demo"><span>View Demo</span></a> <a href="/lab/jquery/demo/download/jquery-menu-slider.zip" class="demo"><span>Download Source Code</span></a></p>
<h3 class="clear">Adding Vertical Slider Animation</h3>
<p>Check out our follow up post &#8211; <a href="/blog/index.php/jquery/jquery-tutorial-adding-vertical-animation-jquery-slider-menu/">jQuery Tutorial – Adding Vertical Animation to the Slider Menu</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/jquery-tutorial-create-a-jquery-menu-slider/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Create An Automatic Content Filter Using jQuery &amp; CSS Classes</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/create-an-automatic-content-filter-using-jquery-css-classes/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/create-an-automatic-content-filter-using-jquery-css-classes/#comments</comments>
		<pubDate>Sun, 05 Jun 2011 12:08:32 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=1897</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/create-an-automatic-content-filter-using-jquery-css-classes/"><img align="left" hspace="5" width="150" src="/media/images/jquery_automatic_class_filter_tutorial.png" class="alignleft wp-post-image tfe" alt="" title="" /></a><p><img src="/media/images/jquery_automatic_class_filter_tutorial.png" alt="" /></p>
<p>The objective of today&#8217;s jQuery tutorial is to automatically generate a list of &#8220;category&#8221; links from CSS class names and use these links to filter our HTML content.</p>
<p>For the tutorial demo we are going to use a list of links for our jQuery tutorials, which we would like to filter by subject/category. This technique however is useful for &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/create-an-automatic-content-filter-using-jquery-css-classes/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p><img src="/media/images/jquery_automatic_class_filter_tutorial.png" alt="" /></p>
<p>The objective of today&#8217;s jQuery tutorial is to automatically generate a list of &#8220;category&#8221; links from CSS class names and use these links to filter our HTML content.</p>
<p>For the tutorial demo we are going to use a list of links for our jQuery tutorials, which we would like to filter by subject/category. This technique however is useful for any kind of HTML elements including; images, creating dependant select lists, unordered/ordered lists, etc and is ideal for content that needs to be listed under multiple categories or creating portfolios.</p>
<p>Since the actual filter list is generated dynamically we can quickly and easily add/edit/delete items that we would like to filter as well as change the categories.</p>
<p><a href="/lab/jquery/demo/jquery_demo_create_class_filter.htm" class="demo">View Demo</a><a href="/lab/jquery/demo/download/jquery-create-class-filter.zip" class="demo">Download Source Files</a></p>
<h3 class="clear">HTML List</h3>
<p>First we create our list of items to be filtered. For the purpose of the tutorial we wont include all of the list items show in the demo. On the few samples though note the class names added to each item &#8211; these are our categories/tags that we would like to use for filtering:</p>
<pre class="brush: plain; title: ; notranslate">
&lt;ul id=&quot;demo-list&quot;&gt;
  &lt;li&gt;
    &lt;a href=&quot;/lab/jquery/demo/jquery_demo_light_weight_animated_slider.htm&quot; class=&quot;menus animation horizontal&quot;&gt;Lightweight Slider&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;/lab/jquery/demo/jquery_simple_horizontal_accordion.htm&quot; class=&quot;menus animation horizontal&quot;&gt;Simple Horizontal Accordion&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;/lab/jquery-mega-drop-down-menu-plugin/getting-started/&quot; class=&quot;menus plugins&quot;&gt;jQuery Mega Drop Down Menu Plugin&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;/lab/jquery/demo/jquery_animation_form_validation_errors.htm&quot; class=&quot;forms validation ajax animation&quot;&gt;Animated Error Messages &amp;amp; Form Validation&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;/lab/jquery/demo/jquery_demo_image_swap_gallery.htm&quot; class=&quot;images&quot;&gt;Ultimate Image Swap Gallery with 3 Lines of Code&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href=&quot;/lab/jquery/demo/jquery_demo_slick_jquery_captions.htm&quot; class=&quot;images animation&quot;&gt;jQuery Fading Image Captions&lt;/a&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</pre>
<h3>The jQuery Code</h3>
<p>There are basically 2 main parts to the jQuery:</p>
<p>Create The Filter Links &#8211; this involves retrieving all of the item classes and create a list of filter links based on the class names</p>
<p>A function to filter the demo list using the above links</p>
<h4>1. Create The Filter Links</h4>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function() {

// map the classes for each item into a new array
classes = $(&quot;#demo-list li a&quot;).map(function(){
    return $(this).attr(&quot;class&quot;).split(' ');
});

// create list of distinct items only
var classList = distinctList(classes);

// generate the list of filter links
var tagList = '&lt;ul id=&quot;tag-list&quot;&gt;&lt;/ul&gt;';
tagItem = '&lt;li&gt;&lt;a href=&quot;#&quot; class=&quot;active&quot;&gt;all&lt;/a&gt;&lt;/li&gt;';

// loop through the list of classes &amp; add link
$.each(classList, function(index,value){
    var value = value.replace(&quot;-&quot;, &quot; &quot;);
    tagItem += '&lt;li&gt;&lt;a href=&quot;#&quot;&gt;'+value+'&lt;/a&gt;&lt;/li&gt;';
});

// add the filter links before the list of items
$(&quot;#demo-list&quot;).before($(tagList).append(tagItem));

});

// Function to create a distinct list from array
function distinctList(inputArray){
	var i;
	var length = inputArray.length;
	var outputArray = [];
	var temp = {};
	for (i = 0; i &lt; length; i++) {
		temp[inputArray[i]] = 0;
    }
    for (i in temp) {
        outputArray.push(i);
	}
	return outputArray;
}
</pre>
<p>In the above code we first retrieve all of the class names from our list of demo links using jQuery&#8217;s map function.</p>
<p>This will create an array of containing all class names. In order to convert it to an array containing a distinct list of class names we pass our array to the function at the end &#8211; distinctList().</p>
<p>With the cleaned up output from our distinctList() function we then loop through the array and create a filter link for each item. Note that we create the complete filter links list before we insert the HTML &#8211; this will help improve performance since we only need to manipulate the DOM once.</p>
<p>We have also included an &#8220;all&#8221; link, which will allow us to reset the demo list filter and show all items.b</p>
<div class="banner-horizontal">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-7740611438413740";
/* Banner Mid Post */
google_ad_slot = "8625321051";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<h4>2. Filtering the Demo List</h4>
<pre class="brush: jscript; title: ; notranslate">
// filter the demo list when the filter links are clicked
$('#tag-list li a').live('click',function(e){

    // allows filter categories using multiple words
    var getText = $(this).text().replace(&quot; &quot;, &quot;-&quot;);
    if(getText == 'all'){
        $(&quot;#demo-list li a&quot;).fadeIn();
    } else {
        $(&quot;#demo-list li a&quot;).fadeOut();
        $(&quot;#demo-list li a.&quot;+getText).fadeIn();
    }

    // add class &quot;active&quot; to current filter item
    $('#tag-list li a').removeClass('active');
    $(this).addClass('active');

    // prevent the page scrolling to the top of the screen
    e.preventDefault();
});
</pre>
<p>The demo list items will be filtered when the filter links are clicked. Since we create the filter links on the fly we need to use the &#8220;live&#8221; function to bind the categories.</p>
<p>The function allows us to use multiple words for category names by adding them as class names with hyphens &#8211; e.g. horizontal-menus would appear in the filter links as &#8220;horizontal menus&#8221;.</p>
<p>For this demo we will use fadeIn and fadeOut to show/hide the demo links. This can easily be substituted by any of the animation styles to suit your own tastes.</p>
<p>Finally at the end of our click function we add code to give the current filter item the class &#8220;active&#8221; and use e.preventDefault() to stop the browser scrolling to the top of the screen when the filter links are clicked.</p>
<h3>The Complete jQuery Code</h3>
<p>The complete jQuery code for our automatic content filter is:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function() {

// map the classes for each item into a new array
classes = $(&quot;#demo-list li a&quot;).map(function(){
    return $(this).attr(&quot;class&quot;).split(' ');
});

// create list of distinct items only
var classList = distinctList(classes);

// generate the list of filter links
var tagList = '&lt;ul id=&quot;tag-list&quot;&gt;&lt;/ul&gt;';
tagItem = '&lt;li&gt;&lt;a href=&quot;#&quot; class=&quot;active&quot;&gt;all&lt;/a&gt;&lt;/li&gt;';

// loop through the list of classes &amp; add link
$.each(classList, function(index,value){
    var value = value.replace(&quot;-&quot;, &quot; &quot;);
    tagItem += '&lt;li&gt;&lt;a href=&quot;#&quot;&gt;'+value+'&lt;/a&gt;&lt;/li&gt;';
});

// add the filter links before the list of items
$(&quot;#demo-list&quot;).before($(tagList).append(tagItem));

// filter the demo list when the filter links are clicked
$('#tag-list li a').live('click',function(e){

    // allows filter categories using multiple words
    var getText = $(this).text().replace(&quot; &quot;, &quot;-&quot;);
    if(getText == 'all'){
        $(&quot;#demo-list li a&quot;).fadeIn();
    } else {
        $(&quot;#demo-list li a&quot;).fadeOut();
        $(&quot;#demo-list li a.&quot;+getText).fadeIn();
    }

    // add class &quot;active&quot; to current filter item
    $('#tag-list li a').removeClass('active');
    $(this).addClass('active');

    // prevent the page scrolling to the top of the screen
    e.preventDefault();
});
});

// Function to create a distinct list from array
function distinctList(inputArray){
	var i;
	var length = inputArray.length;
	var outputArray = [];
	var temp = {};
	for (i = 0; i &lt; length; i++) {
		temp[inputArray[i]] = 0;
    }
    for (i in temp) {
        outputArray.push(i);
	}
	return outputArray;
}
</pre>
<p><a href="/lab/jquery/demo/jquery_demo_create_class_filter.htm" class="demo">View Demo</a><a href="/lab/jquery/demo/download/jquery-create-class-filter.zip" class="demo">Download Source Files</a></p>
<div class="clear"></div>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/create-an-automatic-content-filter-using-jquery-css-classes/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Adding a WordPress Menu To a Non-WordPress Page</title>
		<link>http://www.designchemical.com/blog/index.php/website-coding/adding-a-wordpress-menu-to-a-non-wordpress-page/</link>
		<comments>http://www.designchemical.com/blog/index.php/website-coding/adding-a-wordpress-menu-to-a-non-wordpress-page/#comments</comments>
		<pubDate>Sat, 14 May 2011 23:25:04 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[Wordpress Tips]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=1881</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/website-coding/adding-a-wordpress-menu-to-a-non-wordpress-page/"><img align="left" hspace="5" width="150" src="http://www.designchemical.com/blog/wp-content/plugins/thumbnail-for-excerpts/jquery_code.png" class="alignleft wp-post-image tfe" alt="" title="" /></a><p>If you are developing a site that uses WordPress as a CMS for part of the website and custom php pages for other sections it can be useful to utilise the functions built into WordPress on non-Wordpress pages.</p>
<p>One useful example is to use the WordPress menu system to manage the site&#8217;s menus. With its ability to add custom links, &#8230; <a href="http://www.designchemical.com/blog/index.php/website-coding/adding-a-wordpress-menu-to-a-non-wordpress-page/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>If you are developing a site that uses WordPress as a CMS for part of the website and custom php pages for other sections it can be useful to utilise the functions built into WordPress on non-Wordpress pages.</p>
<p>One useful example is to use the WordPress menu system to manage the site&#8217;s menus. With its ability to add custom links, this offers a powerful solution to handling the complete website&#8217;s navigation.</p>
<h3>Adding The WordPress Functions</h3>
<p>Setting this up is actually very simple and just requires a few lines of code in the head of the page to add the necessary WordPress functions:</p>
<pre class="brush: plain; title: ; notranslate">
require('blog/wp-config.php');
$wp-&gt;init();
$wp-&gt;parse_request();
$wp-&gt;query_posts();
$wp-&gt;register_globals();
</pre>
<p>Obviously you need to change the path to the wp-config file to be the same as the directory for your WordPress installlation.</p>
<h3>The WordPress Menu Function</h3>
<p>To add a WordPress menu to our page we then just use the wp_nav_menu() function as we would do in our WordPress theme files. The function accepts all of the same parameters, which allows you to customise various aspects.</p>
<p>For our tutorial demo we are going to add the mega menu, which is set up for the <a href="/lab/demo-wordpress-jquery-mega-menu-plugin/">WordPress mega menu plugin demo page</a>. To identify the menu we use the &#8220;menu&#8221; parameter in the wp_nav_menu function, which accepts the menu slug name &#8211; based on the name you gave your menu in the WordPress admin system &#8211; in our case it is &#8220;mega-menu&#8221;</p>
<pre class="brush: plain; title: ; notranslate">
&lt;?php
    wp_nav_menu( array( 'menu' =&gt; 'mega-menu' ) );
?&gt;
</pre>
<p>And that&#8217;s all there is to it &#8211; just add the function in the page where you want the menu to appear.</p>
<h3>See WordPress Menu Demo</h3>
<p><a href="/lab/jquery/demo/wordpress_external_menu_example.php">Demo of WordPress menu in a non-wordpress page</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/website-coding/adding-a-wordpress-menu-to-a-non-wordpress-page/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Form Validation Using jQuery and Regular Expressions</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/form-validation-using-jquery-and-regular-expressions/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/form-validation-using-jquery-and-regular-expressions/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 02:00:09 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Validation]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=952</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/form-validation-using-jquery-and-regular-expressions/"><img align="left" hspace="5" width="120" height="120" src="http://www.designchemical.com/blog/wp-content/uploads/2010/05/thumb_jquery_code.png" class="alignleft tfe wp-post-image" alt="thumb_jquery_code" title="thumb_jquery_code" /></a><h4>Updated 18th April 2011</h4>
<p>Regular expressions offer an extremely flexible and powerful way of adding validation to your website forms. Combined with jQuery, it allows you to ensure that data sent to the server matches all of your requirements.</p>
<p>In this post I have included several example regular expressions that we have used in our web design projects for validating &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/form-validation-using-jquery-and-regular-expressions/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<h4>Updated 18th April 2011</h4>
<p>Regular expressions offer an extremely flexible and powerful way of adding validation to your website forms. Combined with jQuery, it allows you to ensure that data sent to the server matches all of your requirements.</p>
<p>In this post I have included several example regular expressions that we have used in our web design projects for validating form input.</p>
<p>For this tutorial we assume you know how to create the HTML form and add jQuery to your site. For samples you can refer to previous posts &#8211; <a href="http://www.designchemical.com/blog/index.php/jquery/check-passwords-using-jquery/">check passwords using jQuery</a>, <a href="http://www.designchemical.com/blog/index.php/jquery/email-validation-using-jquery/">email validation using jQuery</a> or view the demo form.</p>
<p class="clear-float"><a href="http://www.designchemical.com/lab/jquery/demo/jquery_regular_expression_validation_samples.htm" class="demo">View Demo</a></p>
<p class="clear">For each example we have created a css class, which can then be assigned to the relevant form element. If you are creating your own validation code/plugin there are obviously more efficient ways of creating a complete validation system but for the tutorial we have kept each regular expression sample separate and also use the &#8220;keyup&#8221; event.</p>
<h3>jQuery To Handle the Submit Button</h3>
<p>In order to use these validation functions in a form we need to add jQuery that will check for the presence of any span elements with the class &#8220;error&#8221;. We do this by using the length property. If the length is > 0 the form submit can be stopped and the user alerted:</p>
<pre class="brush: jscript; title: ; notranslate">
$('#btn-submit').click(function() {
  if($('span.error').length &amp;gt; 0){
    alert('Errors!');
    return false;
  } else {
    $('#btn-submit').after('&lt;span class=&quot;error&quot;&gt;Form Accepted.&lt;/span&gt;');
    return false;
  }
});
</pre>
<p>Now that we have this code to check for errors, we can add any of the examples below to the form.</p>
<div class="banner-horizontal">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-7740611438413740";
/* Banner Mid Post */
google_ad_slot = "8625321051";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<h3>Example 1 &#8211; Validates Numeric Characters Only</h3>
<p>Accepts only 0 &#8211; 9</p>
<pre class="brush: jscript; title: ; notranslate">
$('.keyup-numeric').keyup(function() {
    $('span.error-keyup-1').hide();
    var inputVal = $(this).val();
    var numericReg = /^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$/;
    if(!numericReg.test(inputVal)) {
        $(this).after('&lt;span class=&quot;error error-keyup-1&quot;&gt;Numeric characters only.&lt;/span&gt;');
    }
});
</pre>
<h3>Example 2 &#8211; No Special Characters</h3>
<p>Allows only letters, numbers and spaces. All other characters will return an error.</p>
<pre class="brush: jscript; title: ; notranslate">
$('.keyup-characters').keyup(function() {
    $('span.error-keyup-2').remove();
    var inputVal = $(this).val();
    var characterReg = /^\s*[a-zA-Z0-9,\s]+\s*$/;
    if(!characterReg.test(inputVal)) {
        $(this).after('&lt;span class=&quot;error error-keyup-2&quot;&gt;No special characters allowed.&lt;/span&gt;');
    }
});
</pre>
<h3>Example 3 &#8211; Maximum of 8 Characters</h3>
<p>Allows all characters up to a maximum of 8. Useful for passwords, etc. The value can easily be increased/descreased by changing the {0,8}</p>
<pre class="brush: jscript; title: ; notranslate">
$('.keyup-limit-8').keyup(function() {
    $('span.error-keyup-3').remove();
    var inputVal = $(this).val();
    var characterReg = /^([a-zA-Z0-9]{0,8})$/;
    if(!characterReg.test(inputVal)) {
        $(this).after('&lt;span class=&quot;error error-keyup-3&quot;&gt;Maximum 8 characters.&lt;/span&gt;');
    }
});
</pre>
<h3>Example 4 &#8211; US Phone Number</h3>
<p>Allows numbers 2-9 for the first and second group of 3 followed by 0-9 for the last 4 with the groups separated by &#8220;-&#8221; e.g:</p>
<ul>
<li>234-234-1234 = OK</li>
<li>134-234-1234 = Error</li>
<li>234-134-1234 = Error</li>
</ul>
<pre class="brush: jscript; title: ; notranslate">
$('.keyup-phone').keyup(function() {
    $('span.error-keyup-4').remove();
    var inputVal = $(this).val();
    var characterReg = /^[2-9]\d{2}-\d{3}-\d{4}$/;
    if(!characterReg.test(inputVal)) {
        $(this).after('&lt;span class=&quot;error error-keyup-4&quot;&gt;Format xxx-xxx-xxxx&lt;/span&gt;');
    }
});
</pre>
<h3>Example 5 &#8211; Validate Date Format</h3>
<p>Allows date format &#8211; mm/dd/yyyy &#8211; including &#8220;/&#8221;. All other combinations will return errors e.g:</p>
<ul>
<li>01/31/2001 = OK</li>
<li>31/01/2001 = Error</li>
<li>1/01/2001 = Error</li>
</ul>
<pre class="brush: jscript; title: ; notranslate">
$('.keyup-date').keyup(function() {
    $('span.error-keyup-5').remove();
    var inputVal = $(this).val();
    var dateReg = /^[0,1]?\d{1}\/(([0-2]?\d{1})|([3][0,1]{1}))\/(([1]{1}[9]{1}[9]{1}\d{1})|([2-9]{1}\d{3}))$/;
    if(!dateReg.test(inputVal)) {
        $(this).after('&lt;span class=&quot;error error-keyup-5&quot;&gt;Invalid date format.&lt;/span&gt;');
    }
});
</pre>
<h3>Example 6 &#8211; Check For Possible Fake Text</h3>
<p>This is an interesting example, which checks for possible fake text being entered into your form. The regex looks for groups of the same letters occuring in groups of 3 or more e.g:</p>
<ul>
<li>foo = OK</li>
<li>fff = Error</li>
</ul>
<pre class="brush: jscript; title: ; notranslate">
$('.keyup-fake').keyup(function() {
    $('span.error-keyup-6').remove();
    var inputVal = $(this).val();
    var fakeReg = /(.)\1{2,}/;
    if(fakeReg.test(inputVal)) {
        $(this).after('&lt;span class=&quot;error error-keyup-6&quot;&gt;Invalid text.&lt;/span&gt;');
    }
});
</pre>
<h3>Example 7 &#8211; Check Email Address Format</h3>
<p>This is a standard regular expression, which is used to validate email addresses to ensure they follow the standard format:</p>
<ul>
<li>email@email.com = OK</li>
<li>email.email.com = Error</li>
</ul>
<pre class="brush: jscript; title: ; notranslate">
$('.keyup-email').keyup(function() {
    $('span.error-keyup-7').remove();
    var inputVal = $(this).val();
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    if(!emailReg.test(inputVal)) {
        $(this).after('&lt;span class=&quot;error error-keyup-7&quot;&gt;Invalid Email Format.&lt;/span&gt;');
    }
});
</pre>
<h3>Example 8 &#8211; No Free Email Addresses</h3>
<p>Another useful email validation regular expression checks for email addresses using free emails &#8211; in the example below we check for yahoo, gmail and hotmail:</p>
<ul>
<li>email@yahoo.com = Error</li>
<li>email@email.com = OK</li>
</ul>
<pre class="brush: jscript; title: ; notranslate">
$('.keyup-email-2').keyup(function() {
    $('span.error-keyup-8').remove();
    var inputVal = $(this).val();
    var emailFreeReg= /^([\w-\.]+@(?!gmail.com)(?!yahoo.com)(?!hotmail.com)(?!aol.com)([\w-]+\.)+[\w-]{2,4})?$/;
    if(!emailFreeReg.test(inputVal)) {
        $(this).after('&lt;span class=&quot;error error-keyup-8&quot;&gt;No Free Email Addresses.&lt;/span&gt;');
    }
});
</pre>
<h3>Example 9 &#8211; Visa Card Number Format</h3>
<p>For an example of validating a credit card we can use the following regular expression, which checks the input against the standard format for Visa credit cards &#8211; All card numbers must start with a 4 &#038; cards may either have 16 digits or 13 digits for older cards:</p>
<ul>
<li>4166000000000000 = OK</li>
<li>4166000000000 = OK</li>
<li>41660000000000001 = Error</li>
<li>2166000000000000 = Error</li>
</ul>
<pre class="brush: jscript; title: ; notranslate">
$('.keyup-cc').keyup(function() {
    $('span.error-keyup-9').remove();
    var inputVal = $(this).val();
    var ccReg = /^4[0-9]{12}(?:[0-9]{3})?$/;
    if(!ccReg.test(inputVal)) {
        $(this).after('&lt;span class=&quot;error error-keyup-9&quot;&gt;Invalid visa card number&lt;/span&gt;');
    }
});
</pre>
<p>Hopefully some of the above examples will be useful for your forms and also help demonstrate how powerful regular expressions can be.</p>
<p><a href="http://www.designchemical.com/lab/jquery/demo/jquery_regular_expression_validation_samples.htm" class="demo">View Demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/form-validation-using-jquery-and-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Open External Links In New Browser Window Using jQuery</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/open-external-links-in-new-browser-window-using-jquery/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/open-external-links-in-new-browser-window-using-jquery/#comments</comments>
		<pubDate>Wed, 06 Apr 2011 03:16:29 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=1623</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/open-external-links-in-new-browser-window-using-jquery/"><img align="left" hspace="5" width="150" src="http://www.designchemical.com/blog/wp-content/plugins/thumbnail-for-excerpts/jquery_code.png" class="alignleft wp-post-image tfe" alt="" title="" /></a><p>Since one of our earlier posts &#8211; How To Open Links In a New Browser Window we have had requests at how this can be automated so that only external links are opened in a new window without having to add class &#8220;external&#8221; to every link.</p>
<p>This can be done in a couple of ways depending on how your links &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/open-external-links-in-new-browser-window-using-jquery/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>Since one of our earlier posts &#8211; <a href="/blog/index.php/jquery/open-links-in-new-browser-window-using-jquery/">How To Open Links In a New Browser Window</a> we have had requests at how this can be automated so that only external links are opened in a new window without having to add class &#8220;external&#8221; to every link.</p>
<p>This can be done in a couple of ways depending on how your links are structured. As well as giving the code for external links, this tutorial also shows a good example of how to combine and use jQuery selectors to filter:</p>
<h3>Method 1 &#8211; Links With Complete URLs</h3>
<p>If your site uses complete URLs, including the domain name, for all links we can identify the external links by selecting those that do not contain your domain name. For this we use a combination of both the not() and :contains() selectors:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function($){
    $('a').not(':contains(http://www.designchemical.com)').click(function(){
        this.target = &quot;_blank&quot;;
    });
});
</pre>
<p>The above code will therefore identify any link that does not contain http://www.designchemical.com and open this in a new browser window.</p>
<p><a href="/lab/jquery/demo/jquery_demo_open_external_links_new_browser_window_1.htm" class="demo">View Demo 1</a></p>
<h3 class="clear">Method 2 &#8211; Only External Links Use Complete URLs</h3>
<p>If only external links use complete URLs we can just use contains() selector to identify those links with http or https:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function($){
    $('a:contains(http)').click(function(){
        this.target = &quot;_blank&quot;;
    });
});
</pre>
<p><a href="/lab/jquery/demo/jquery_demo_open_external_links_new_browser_window_2.htm" class="demo">View Demo 2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/open-external-links-in-new-browser-window-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Image Swap Gallery with Just 3 Lines of Code!</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/jquery-image-swap-gallery/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/jquery-image-swap-gallery/#comments</comments>
		<pubDate>Sat, 26 Mar 2011 08:34:10 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[images]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=1571</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/jquery-image-swap-gallery/"><img align="left" hspace="5" width="150" src="/media/images/jquery_image_swap_gallery.jpg" class="alignleft wp-post-image tfe" alt="" title="" /></a><p class="text-center"><img src="/media/images/jquery_image_swap_gallery.jpg" alt="" /></p>
<p>Our earlier post, Quick and Easy jQuery Image Swap has always been popular, so today we are going to use this code to create the ultimate jQuery image swap gallery with just 3 lines of code and 2 lines of CSS.</p>
<p>And here is the jQuery code:</p>
<p>View The DemoDownload Source Files</p>
<p class="clear">A great example of how &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/jquery-image-swap-gallery/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p class="text-center"><img src="/media/images/jquery_image_swap_gallery.jpg" alt="" /></p>
<p>Our earlier post, <a href="/blog/index.php/jquery/quick-and-easy-jquery-image-swap/">Quick and Easy jQuery Image Swap</a> has always been popular, so today we are going to use this code to create the ultimate jQuery image swap gallery with just 3 lines of code and 2 lines of CSS.</p>
<p>And here is the jQuery code:</p>
<pre class="brush: jscript; title: ; notranslate">
$(&quot;#gallery li img&quot;).hover(function(){
	$('#main-img').attr('src',$(this).attr('src').replace('thumb/', ''));
});
</pre>
<p><a href="/lab/jquery/demo/jquery_demo_image_swap_gallery.htm" class="demo">View The Demo</a><a href="/lab/jquery/demo/download/ultimate-jquery-image-swap-gallery.zip" class="demo">Download Source Files</a></p>
<p class="clear">A great example of how jQuery can be extremely simple and effective.</p>
<h3>The Gallery HTML</h3>
<p>All we need for the gallery is the initial, main image and an unordered list holding the image thumbnails.</p>
<pre class="brush: plain; title: ; notranslate">
&lt;div id=&quot;gallery&quot;&gt;
	&lt;img src=&quot;images/gallery/img_1.jpg&quot; alt=&quot;&quot; id=&quot;main-img&quot; /&gt;
	&lt;ul&gt;
	  &lt;li&gt;&lt;img src=&quot;images/gallery/thumb/img_1.jpg&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
	  &lt;li&gt;&lt;img src=&quot;images/gallery/thumb/img_3.jpg&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
	  &lt;li&gt;&lt;img src=&quot;images/gallery/thumb/img_4.jpg&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
	  &lt;li&gt;&lt;img src=&quot;images/gallery/thumb/img_5.jpg&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
	  &lt;li&gt;&lt;img src=&quot;images/gallery/thumb/img_6.jpg&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
	  &lt;li&gt;&lt;img src=&quot;images/gallery/thumb/img_7.jpg&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/div&gt;
</pre>
<p>Our thumbnail images have the same file name as the larger versions and these are put into a folder called &#8220;thumb&#8221;, which is in the same directory as the main images &#8211; this is important for our gallery code to work as the image URL is obtained by getting the thumbnail URL and removing the &#8220;/thumb&#8221;.</p>
<h3>Styling The Gallery</h3>
<p>Definitely not rocket science here &#8211; a total of 2 CSS rules:</p>
<pre class="brush: plain; title: ; notranslate">
#gallery li {
display: inline;
margin-right: 3px;
}
#gallery #main-img {
background: url(images/bg_img.png) no-repeat 0 0;
padding: 26px;
}
</pre>
<h3>Adding Image Preload Function</h3>
<p>Although the 3 lines of jQuery will work, we can make the gallery far better if we use our <a href="/blog/index.php/jquery/create-image-preloader-image-swap-function-jquery/">image preload function</a>, from our previous tutorial.</p>
<p>The complete jQuery for the gallery plus preload:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function() {
	// Image swap on hover
	$(&quot;#gallery li img&quot;).hover(function(){
		$('#main-img').attr('src',$(this).attr('src').replace('thumb/', ''));
	});
	// Image preload
	var imgSwap = [];
	 $(&quot;#gallery li img&quot;).each(function(){
		imgUrl = this.src.replace('thumb/', '');
		imgSwap.push(imgUrl);
	});
	$(imgSwap).preload();
});
$.fn.preload = function() {
    this.each(function(){
        $('&lt;img/&gt;')[0].src = this;
    });
}
</pre>
<p>And that&#8217;s basically all there is to it.</p>
<p>Although it may not have fancy fade/zoom/slide/etc effects and look particularly slick, it is a nice and easy example of how to apply the jQuery image swap on hover function.</p>
<p>You can obviously improve on the features but if you are looking for a simple solution without having to understand setting up and styling a complicated gallery plugin (and lets face it some of them are complicated!), then this is about as simple as it gets!</p>
<p><a href="/lab/jquery/demo/jquery_demo_image_swap_gallery.htm" class="demo">View The Demo</a><a href="/lab/jquery/demo/download/ultimate-jquery-image-swap-gallery.zip" class="demo">Download Source Files</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/jquery-image-swap-gallery/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
		<item>
		<title>WordPress Tutorial – Create Your own Custom Vertical Mega Menu</title>
		<link>http://www.designchemical.com/blog/index.php/wordpress-plugins/wordpress-tutorial-create-your-own-custom-vertical-mega-menu/</link>
		<comments>http://www.designchemical.com/blog/index.php/wordpress-plugins/wordpress-tutorial-create-your-own-custom-vertical-mega-menu/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 17:21:39 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery Plugins]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[Wordpress Plugins]]></category>
		<category><![CDATA[Wordpress Tips]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[mega menus]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vertical]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=1546</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/wordpress-plugins/wordpress-tutorial-create-your-own-custom-vertical-mega-menu/"><img align="left" hspace="5" width="150" src="/media/images/custom_vertical_mega_menu.jpg" class="alignleft wp-post-image tfe" alt="Custom Vertical Mega Menu" title="" /></a><p><img src="/media/images/custom_vertical_mega_menu.jpg" alt="Custom Vertical Mega Menu" /></p>
<p>In our last menu tutorial we looked at creating a custom style sheet for the mega drop down menu plugin. Today we are going to go through the jQuery Vertical Mega Menu Plugin and how we can use the plugin&#8217;s built in CSS classes combined with the inherent WordPress menu classes to create a completely customised menu.</p>
<p>The sample &#8230; <a href="http://www.designchemical.com/blog/index.php/wordpress-plugins/wordpress-tutorial-create-your-own-custom-vertical-mega-menu/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p><img src="/media/images/custom_vertical_mega_menu.jpg" alt="Custom Vertical Mega Menu" /></p>
<p>In our last menu tutorial we looked at <a href="/blog/index.php/tutorials/wordpress-tutorial-create-your-own-custom-mega-menu-styles/">creating a custom style sheet for the mega drop down menu</a> plugin. Today we are going to go through the <a href="/blog/index.php/wordpress-plugins/wordpress-plugin-jquery-vertical-mega-menu/">jQuery Vertical Mega Menu Plugin</a> and how we can use the plugin&#8217;s built in CSS classes combined with the inherent WordPress menu classes to create a completely customised menu.</p>
<p>The sample CSS file in the demo can also be used as a template for your own WordPress vertical mega menu styles:</p>
<p><a href="/lab/demo-custom-vertical-mega-menu-styling/" class="demo">View Final Menu Demo</a><a href="/lab/jquery/demo/download/custom-vertical-mega-menu-1.zip" class="demo">Download source code</a></p>
<p class="clear">This tutorial assumes that you understand at least the basics of CSS and HTML, know how to create a custom menu using the admin system in WordPress 3.0 and, of course, use our Vertical Mega menu plugin as some of the CSS selectors are specific to this plugin.</p>
<h3>The Objectives</h3>
<p>For the tutorial we will create a mega menu for a store selling sports clothing/equipment. In addition to the basic minimum styles required to create the vertical mega menu we will add a drop-shadow to the menu container and also customise all 3 of the sub-menus.</p>
<h4>Footwear Custom Menu</h4>
<p>For this menu we will customise each row to add labels showing Mens/Ladies as well as add background images for each of the product groups.</p>
<p class="text-center"><img src="/media/images/custom_vertical_mega_menu_1.jpg" alt="Footwear Custom Menu" /></p>
<h4>Jackets Sub-Menu</h4>
<p>Usually the mega menu works best with 3 levels of navigation. The jackets sub-menu gives an example of how you can still customise the mega menu with only 2 menu levels.</p>
<p class="text-center"><img src="/media/images/custom_vertical_mega_menu_2.jpg" alt="Jackets Custom Menu" /></p>
<h4>Sports Bags Sub-Menu</h4>
<p>Add background images to each sub-menu.</p>
<p class="text-center"><img src="/media/images/custom_vertical_mega_menu_3.jpg" alt="Sports Bags Custom Menu" /></p>
<h3>Creating The Vertical Mega Menu</h3>
<h4>The Basic Mega Menu CSS</h4>
<p>The following CSS code gives the minimum styling required to create the standard mega menu structure without any specifc styles for the menu options. Using this code our menu looks like this:</p>
<p class="text-center"><img src="/media/images/basic_vertical_mega_menu_1.jpg" alt="Basic Mega Menu" /></p>
<p><a href="/lab/demo-basic-vertical-mega-menu-styling/" class="demo">View Basic Mega Menu Demo</a></p>
<p class="clear">Still mega but definitely not as pretty!</p>
<div class="banner-horizontal">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-7740611438413740";
/* Banner Mid Post */
google_ad_slot = "8625321051";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<p>The CSS contains notes on any essential styles</p>
<pre class="brush: plain; title: ; notranslate">
/* Main menu styling */
.dcjq-vertical-mega-menu .menu li a {
display: block;
color: #000;
padding: 11px 38px 11px 25px;
text-shadow: 1px 1px 1px #fff;
text-decoration: none;
border-bottom: 1px solid #999;
background: url(images/bg_nav.png) repeat-x 0 0;
}
.dcjq-vertical-mega-menu .menu li a:hover, .dcjq-vertical-mega-menu .menu li.mega-hover a {
background-position: 0 -40px;
color: #fff;
text-shadow: 1px 1px 1px #000;
}

/* Add arrow icon to parent links */
.dcjq-vertical-mega-menu .menu li a.dc-mega {
position: relative; /* Required since icons are positioned absolutely */
}
.dcjq-vertical-mega-menu .menu li a .dc-mega-icon {
display: block;
position: absolute;
top: 14px;
right: 15px;
width: 6px;
height: 8px;
background: url(images/arrow_right.png) no-repeat -6px 0;
}
.dcjq-vertical-mega-menu .menu li a:hover .dc-mega-icon, .dcjq-vertical-mega-menu .menu li.mega-hover a .dc-mega-icon {
background-position: 0 0;
}

/* Mega menu container */
.dcjq-vertical-mega-menu .menu li .sub-container {
position: absolute; /* Required */
overflow: hidden;
background: url(images/bg_menu.png) no-repeat 100% 100%; /* Add the drop shadow image */
padding: 0 13px 17px 0; /* Padding for drop shadow */
}
.dcjq-vertical-mega-menu .menu li .sub-container .sub {
border: none;
padding: 15px 15px 5px 15px;
background: #fff url(images/bg_grad_top.png) repeat-x 0 0;
border-top: 1px solid #ccc;
border-right: 1px solid #bbb;
border-bottom: 1px solid #bbb;
border-left: 1px solid #ccc;
}
.dcjq-vertical-mega-menu .menu li .sub .row {
width: 100%; overflow: hidden; /* Required to clear floats for each row */
}
.dcjq-vertical-mega-menu .menu li .sub li {
float: none;
width: 160px; /* Set sub-menu width */
font-weight: normal;
}
.dcjq-vertical-mega-menu .menu li .sub li.mega-hdr {
float: left; /* Required */
margin: 0 5px 10px 5px;
}
.dcjq-vertical-mega-menu .menu li .sub a, .dcjq-vertical-mega-menu .menu.left li .sub a {
background: none;
border: none;
text-shadow: none;
float: none;
color: #000;
display: block;
text-decoration: none;
font-size: 0.9em;
margin-bottom: 0;
}
.dcjq-vertical-mega-menu .menu li .sub li.mega-hdr a.mega-hdr-a { /* Sub-menu headings */
background: url(images/bg_nav.png) repeat-x 0 -40px;
padding: 5px;
margin-bottom: 5px;
text-transform: uppercase;
font-weight: bold;
color: #fff;
text-shadow: 1px 1px 1px #000;
text-align: center;
}
.dcjq-vertical-mega-menu .menu li .sub li.mega-hdr a.mega-hdr-a:hover {
color: #000;
text-shadow: none;
}
.dcjq-vertical-mega-menu .menu .sub li.mega-hdr li {
margin-bottom: 3px;
}
.dcjq-vertical-mega-menu .menu .sub li a {
padding: 3px 3px 3px 15px;
background: url(images/bullet.png) no-repeat 3px 8px;
font-weight: normal;
text-transform: capitalize; font-size: 12px;
}
.dcjq-vertical-mega-menu .menu .sub li a:hover {
color: #fff;
background: #000 url(images/bullet_white.png) no-repeat 5px 8px;
}
.dcjq-vertical-mega-menu .menu .sub ul li {
padding-right: 0;
}

/* Styling for menu items with only 2 levels */
.dcjq-vertical-mega-menu .menu li .sub-container.non-mega .sub {
padding: 10px;
background: #fff;
}
.dcjq-vertical-mega-menu .menu li .sub-container.non-mega li {
padding: 0;
margin: 0;
width: 150px;
float: none;
}
</pre>
<h4>Custom Styling</h4>
<p>In order to customise the menu you will need the menu item ID&#8217;s that WordPress automatically assigns to the HTML list items. To get these you can view the source code for the menu in your own site. The ID follows the format &#8220;menu-item-#&#8221;, where # is a unique number assigned by WordPress.</p>
<p>It can get a little confusing wading through the source code so it&#8217;s best to work out first which items need to have additional CSS rules. The list items that will be customised and their ID&#8217;s in our demo are:</p>
<ul class="content-list">
<li>Footwear (ID menu-item-1) &#8211; For adding the &#8220;Mens&#8221; &amp; &#8220;Ladies&#8221; labels to the rows</li>
<li>Nike Mens (ID menu-item-4)</li>
<li>Adidas Mens (ID menu-item-6)</li>
<li>Gola Mens (ID menu-item-7)</li>
<li>Nike Ladies (ID menu-item-8)</li>
<li>Adidas Ladies (ID menu-item-10)</li>
<li>Gola Ladies (ID menu-item-11)</li>
</ul>
<ul class="content-list">
<li>Jackets (ID menu-item-2) &#8211; Overide the standard styling for only 2 levels of navigation</li>
<li>Jacket 1 (ID menu-item-12)</li>
<li>Jacket 2 (ID menu-item-13)</li>
<li>Jacket 3 (ID menu-item-14)</li>
</ul>
<ul class="content-list">
<li>Sports Bags (ID menu-item-3) &#8211; Add padding to top of all bag sub-menus</li>
<li>Golf Bags (ID menu-item-15)</li>
<li>Sports Bags (ID menu-item-17)</li>
<li>Tennis Bags (ID menu-item-18)</li>
</ul>
<h4>Custom CSS For Footwear</h4>
<pre class="brush: plain; title: ; notranslate">
/* Footwear */
.dcjq-vertical-mega-menu .menu li#menu-item-1 .sub .row {
padding: 10px 10px 0 40px; /* Pad the rows to add the background labels */
margin-bottom: 10px;
border: 1px solid #ccc;
background: url(images/mens.png) no-repeat 0 center; /* Mens row background image */
}
.dcjq-vertical-mega-menu .menu li#menu-item-1 .sub .row.last {
background-image: url(images/ladies.png); /* Ladies row background image */
}
.dcjq-vertical-mega-menu .menu li#menu-item-1 .sub li.mega-hdr {
padding: 75px 0 0; /* Padding for top of each sub-menu for background images */
}

/* Add the background images */
li#menu-item-4.mega-hdr {background: url(images/nike.png) no-repeat center 0;}
li#menu-item-6.mega-hdr {background: url(images/adidas_1.jpg) no-repeat center 0;}
li#menu-item-7.mega-hdr {background: url(images/gola_1.jpg) no-repeat center 0;}
li#menu-item-8.mega-hdr {background: url(images/nike_2.jpg) no-repeat center 0;}
li#menu-item-10.mega-hdr {background: url(images/adidas_2.jpg) no-repeat center 0;}
li#menu-item-11.mega-hdr {background: url(images/gola_2.jpg) no-repeat center 0;}
</pre>
<h4>Custom CSS For Jackets</h4>
<p>The jackets are slightly different to the other 2 since the menu only have 2 levels of navigation. The CSS below will float each item and create a larger menu container.</p>
<pre class="brush: plain; title: ; notranslate">
/* Jackets */
.dcjq-vertical-mega-menu .menu li#menu-item-2 .sub-container.non-mega .sub {
width: 480px; /* Required to overide styling for 2-levels */
height: 180px; /* Required */
padding: 20px 10px 10px;
}
.dcjq-vertical-mega-menu .menu li#menu-item-2 .sub-container.non-mega li {
float: left;
}
li#menu-item-12, li#menu-item-13, li#menu-item-14{
padding: 150px 0 0; /* Padding for top of each sub-menu for background images */
margin-right: 10px;
}

/* Add the background images */
li#menu-item-12 {background: url(images/jacket_1.jpg) no-repeat center 0;}
li#menu-item-13 {background: url(images/jacket_2.jpg) no-repeat center 0;}
li#menu-item-14 {background: url(images/jacket_3.jpg) no-repeat center 0;}
</pre>
<h4>Custom CSS For Sports Bags</h4>
<pre class="brush: plain; title: ; notranslate">
/* Sports Bags */
li#menu-item-3 li.mega-hdr {
padding: 120px 0 0; /* Padding for top of each sub-menu for background images */
}

/* Add the background images */
li#menu-item-15.mega-hdr {background: url(images/bag_1.jpg) no-repeat center 0;}
li#menu-item-17.mega-hdr {background: url(images/bag_3.jpg) no-repeat center 0;}
li#menu-item-18.mega-hdr {background: url(images/bag_4.jpg) no-repeat center 0;}
</pre>
<p>That&#8217;s basically it! Using the above techniques you can pretty much customise the menu to suite most requirements.</p>
<p>Download the source code below for a complete working copies of both the basic and customised menus.</p>
<p><a href="/lab/demo-custom-vertical-mega-menu-styling/" class="demo">View Final Menu Demo</a><a href="/lab/jquery/demo/download/custom-vertical-mega-menu-1.zip" class="demo">Download source code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/wordpress-plugins/wordpress-tutorial-create-your-own-custom-vertical-mega-menu/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Live Text Search Function Using jQuery</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/live-text-search-function-using-jquery/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/live-text-search-function-using-jquery/#comments</comments>
		<pubDate>Mon, 14 Mar 2011 12:34:13 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=1495</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/live-text-search-function-using-jquery/"><img align="left" hspace="5" width="150" src="http://www.designchemical.com/blog/wp-content/plugins/thumbnail-for-excerpts/jquery_code.png" class="alignleft wp-post-image tfe" alt="" title="" /></a><p>Today we are going to look at using jQuery to create a &#8220;live search&#8221; feature for your website. With just a few lines of code and a single text input box you can add a text filter to any site content.</p>
<p>For the tutorial we will create a search feature for our blog comments, although the same function can easily &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/live-text-search-function-using-jquery/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>Today we are going to look at using jQuery to create a &#8220;live search&#8221; feature for your website. With just a few lines of code and a single text input box you can add a text filter to any site content.</p>
<p>For the tutorial we will create a search feature for our blog comments, although the same function can easily be applied to any elements by changing the selector.</p>
<h3>The Search Box HTML</h3>
<p>To capture the search text all we need is a simple input text field. To make the feature a little more exciting we are also going to show the number of results underneath the text input. For this we need to add a div tag with the ID &#8211; &#8220;filter-count&#8221;</p>
<pre class="brush: plain; title: ; notranslate">
&lt;form id=&quot;live-search&quot; action=&quot;&quot; class=&quot;styled&quot; method=&quot;post&quot;&gt;
    &lt;fieldset&gt;
        &lt;input type=&quot;text&quot; class=&quot;text-input&quot; id=&quot;filter&quot; value=&quot;&quot; /&gt;
        &lt;span id=&quot;filter-count&quot;&gt;&lt;/span&gt;
    &lt;/fieldset&gt;
&lt;/form&gt;
</pre>
<p>Give the input field a unique ID since we will need this to capture the users text.</p>
<h3>The Comments List</h3>
<p>Our comments list is structured using an ordered list &#8211; e.g.</p>
<pre class="brush: plain; title: ; notranslate">
&lt;ol class=&quot;commentlist&quot;&gt;
  &lt;li&gt;Comment #1&lt;/li&gt;
  &lt;li&gt;Comment #2&lt;/li&gt;
&lt;/ol&gt;
</pre>
<h3>The jQuery Code</h3>
<p>The jQuery for this feature is relatively easy and all we are doing is basically getting the input text value, checking this against our list of comments and hiding those that do not contain the text phrase. The count of the number of positive results is then displayed in our &#8220;filter-count&#8221; span tag.</p>
<p>Since this is a &#8220;live&#8221; search we will use the &#8220;keyup&#8221; event to initiate the function &#8211; the filtered comment list will therefore update with each character entered.</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function(){
	$(&quot;#filter&quot;).keyup(function(){

		// Retrieve the input field text and reset the count to zero
		var filter = $(this).val(), count = 0;

		// Loop through the comment list
		$(&quot;.commentlist li&quot;).each(function(){

			// If the list item does not contain the text phrase fade it out
			if ($(this).text().search(new RegExp(filter, &quot;i&quot;)) &lt; 0) {
				$(this).fadeOut();

			// Show the list item if the phrase matches and increase the count by 1
			} else {
				$(this).show();
				count++;
			}
		});

		// Update the count
		var numberItems = count;
		$(&quot;#filter-count&quot;).text(&quot;Number of Comments = &quot;+count);
	});
});
</pre>
<p>This jQuery live search can be applied to any elements by changing the &#8220;.commentlist li&#8221; selector.</p>
<p><a href="/lab/jquery/demo/jquery_demo_live_comment_search.htm" class="demo">View jQuery Demo</a></p>
<p>The live text search is also used on all of our blog comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/live-text-search-function-using-jquery/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>New jQuery Plugin – Vertical Mega Menu Plugin</title>
		<link>http://www.designchemical.com/blog/index.php/jquery-plugins/new-jquery-plugin-vertical-mega-menu-plugin/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery-plugins/new-jquery-plugin-vertical-mega-menu-plugin/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 14:10:55 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jQuery Plugins]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[mega menus]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[vertical]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=1408</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery-plugins/new-jquery-plugin-vertical-mega-menu-plugin/"><img align="left" hspace="5" width="150" src="http://www.designchemical.com/blog/wp-content/plugins/thumbnail-for-excerpts/jquery_code.png" class="alignleft wp-post-image tfe" alt="" title="" /></a><p>To compliment the previous plugin for creating horizontal mega menus we have now launched the jQuery vertical mega menu plugin. This now allows you to have all of the benefits of drop down mega menus using menus in the page side columns with the mega menu flying out to the side.</p>
<p>Vertical mega menus offer better useability over standard flyout &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery-plugins/new-jquery-plugin-vertical-mega-menu-plugin/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>To compliment the previous plugin for creating horizontal mega menus we have now launched the jQuery vertical mega menu plugin. This now allows you to have all of the benefits of drop down mega menus using menus in the page side columns with the mega menu flying out to the side.</p>
<p>Vertical mega menus offer better useability over standard flyout style menus with multiple levels.</p>
<p>Using this jQuery plugin you can create vertical mega menus from any standard nested HTML lists. The plugin includes several options, which can be configured for customising the menu:</p>
<ul class="content-list">
<li>Multiple menus per page</li>
<li>3 animation effects for displaying the flyout menu &#8211; show/hide, fade in or slide out</li>
<li>Set speed of animation</li>
<li>Set number of sub menus per row</li>
<li>Set the flyout menu to display on the right or left depending on the position of the menu</li>
</ul>
<p>See the <a href="/lab/jquery-vertical-mega-menu-plugin/getting-started/">jQuery vertical mega menu plugin</a> project pages for complete instructions, demos and to download the plugin including sample code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery-plugins/new-jquery-plugin-vertical-mega-menu-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New jQuery Plugin Released &#8211; jQuery Accordion Menu</title>
		<link>http://www.designchemical.com/blog/index.php/jquery-plugins/new-plugin-released-jquery-accordion-menu/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery-plugins/new-plugin-released-jquery-accordion-menu/#comments</comments>
		<pubDate>Sat, 05 Mar 2011 03:49:35 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jQuery Plugins]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[accordion]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=1349</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery-plugins/new-plugin-released-jquery-accordion-menu/"><img align="left" hspace="5" width="150" src="http://www.designchemical.com/blog/wp-content/plugins/thumbnail-for-excerpts/jquery_code.png" class="alignleft wp-post-image tfe" alt="" title="" /></a><p>We have now launched the jQuery accordion menu plugin used to create the WordPress accordion menu widget plugin.</p>
<p>The jquery plugin has several features, which make it very easy to create fully functional vertical accordion menus from standard HTML nested lists. Options built into the plugin include:</p>
<ul class="content-list">
<li>Option to use either hover or click to activate menu</li>
<li>Menu</li></ul><p> &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery-plugins/new-plugin-released-jquery-accordion-menu/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>We have now launched the jQuery accordion menu plugin used to create the <a href="/blog/index.php/wordpress-plugins/wordpress-plugin-jquery-vertical-accordion-menu-widget/">WordPress accordion menu widget plugin</a>.</p>
<p>The jquery plugin has several features, which make it very easy to create fully functional vertical accordion menus from standard HTML nested lists. Options built into the plugin include:</p>
<ul class="content-list">
<li>Option to use either hover or click to activate menu</li>
<li>Menu state can be saved between pages using cookies</li>
<li>No limit on the number of nested levels</li>
<li>Auto close the menu on mouseout for the hover option</li>
<li>Select option to limit open sub-menus to only one at a time or allow the menu to fully expand</li>
<li>And a new feature &#8211; ability to add a count of the number of child links to each parent menu item &#8211; offering users more information on the menu options available.</li>
</ul>
<p>See the <a href="/lab/jquery-vertical-accordion-menu-plugin/getting-started/">jQuery vertical accordion menu plugin</a> project pages for complete instructions, demos and to download the plugin including sample code and skins.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery-plugins/new-plugin-released-jquery-accordion-menu/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Random Password Generator Using jQuery</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/random-password-generator-using-jquery/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/random-password-generator-using-jquery/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 16:12:08 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[passwords]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=1345</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/random-password-generator-using-jquery/"><img align="left" hspace="5" width="150" src="http://www.designchemical.com/blog/wp-content/plugins/thumbnail-for-excerpts/jquery_code.png" class="alignleft wp-post-image tfe" alt="" title="" /></a><p>Today&#8217;s jQuery post is a useful piece of code that you can add onto your registration forms for creating random passwords using only jQuery. The benefit of providing this system is that it generates stronger passwords than most people would create for themselves so offers extra security for critical applications.</p>
<p>See Random Password Demo Download the source code</p>
<p class="clear">To &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/random-password-generator-using-jquery/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s jQuery post is a useful piece of code that you can add onto your registration forms for creating random passwords using only jQuery. The benefit of providing this system is that it generates stronger passwords than most people would create for themselves so offers extra security for critical applications.</p>
<p><a href="/lab/jquery/demo/jquery_demo_password_generator.htm" class="demo">See Random Password Demo</a> <a href="/lab/jquery/demo/download/jquery_demo_password_generator.zip" class="demo">Download the source code</a></p>
<p class="clear">To actually generate the random password we are going to use a nice little function from <a href="http://jquery-howto.blogspot.com/2009/10/javascript-jquery-password-generator.html">jQuery HowTo Blog &#8211; jQuery Password Generator</a>.</p>
<p>The great thing about this function is that it allows us to set both the password length as well as the option to use special characters.</p>
<p>To use this function then we are going to create a form, add a &#8220;generate password&#8221; link, which will get the random password from the function and insert it into the form and add a second link, which the user clicks if they would like to use the password. If confirmed, we then insert the random password into the password field.</p>
<h3>1. The HTML Form</h3>
<p>Very simple form with just a user name and password field:</p>
<pre class="brush: plain; title: ; notranslate">
&lt;form id=&quot;form-demo&quot; class=&quot;styled&quot; action=&quot;&quot; method=&quot;post&quot;&gt;
    &lt;fieldset&gt;
        &lt;ol&gt;
            &lt;li&gt;
                &lt;label&gt;User Name:&lt;/label&gt;
                &lt;input id=&quot;input-user&quot; type=&quot;text&quot; class=&quot;text-input&quot; name=&quot;user&quot; value=&quot;&quot; /&gt;
            &lt;/li&gt;
            &lt;li&gt;
                &lt;label&gt;Password:&lt;/label&gt;
                &lt;input id=&quot;input-password&quot; type=&quot;password&quot; class=&quot;text-input password&quot; name=&quot;password&quot; value=&quot;&quot; /&gt;
                &lt;a href=&quot;#&quot; class=&quot;link-password&quot; id=&quot;confirm&quot;&gt;Use Password&lt;/a&gt;
                &lt;a href=&quot;#&quot; class=&quot;link-password&quot; id=&quot;generate&quot;&gt;Generate Password&lt;/a&gt;
            &lt;/li&gt;
            &lt;li id=&quot;random&quot;&gt;
            &lt;/li&gt;
            &lt;li&gt;
                &lt;input class=&quot;btn-submit&quot; type=&quot;submit&quot; value=&quot;submit&quot; name=&quot;submit&quot; /&gt;
            &lt;/li&gt;
        &lt;/ol&gt;
    &lt;/fieldset&gt;
&lt;/form&gt;
</pre>
<p>As usual I have used an ordered list for the form structure but obviously you can use whatever style you prefer since its not critical for the password generator. Make sure though that the form has a tag with an id &#8220;random&#8221;, which we are going to use to display the password.</p>
<p>Give both links the same class name as we will use the same click function for both links. The &#8220;confirm&#8221; link can be hidden though since we only require this if the &#8220;generate&#8221; link is clicked. We can do this using CSS as opposed to jQuery:</p>
<pre class="brush: plain; title: ; notranslate">
#confirm {display: none;}
</pre>
<h3>2. jQuery Random Password Function</h3>
<p>Next we add the password generator function jquery code:</p>
<pre class="brush: jscript; title: ; notranslate">
$.extend({
  password: function (length, special) {
    var iteration = 0;
    var password = &quot;&quot;;
    var randomNumber;
    if(special == undefined){
        var special = false;
    }
    while(iteration &lt; length){
        randomNumber = (Math.floor((Math.random() * 100)) % 94) + 33;
        if(!special){
            if ((randomNumber &gt;=33) &amp;&amp; (randomNumber &lt;=47)) { continue; }
            if ((randomNumber &gt;=58) &amp;&amp; (randomNumber &lt;=64)) { continue; }
            if ((randomNumber &gt;=91) &amp;&amp; (randomNumber &lt;=96)) { continue; }
            if ((randomNumber &gt;=123) &amp;&amp; (randomNumber &lt;=126)) { continue; }
        }
        iteration++;
        password += String.fromCharCode(randomNumber);
    }
    return password;
  }
});
</pre>
<p>For full details refer back to the <a href="http://jquery-howto.blogspot.com/2009/10/javascript-jquery-password-generator.html">authors post</a>.</p>
<p>Now we add the jQuery code that will use the above function to generate and insert the new password:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function() {

    $('.link-password').click(function(e){

        // First check which link was clicked
        linkId = $(this).attr('id');
        if (linkId == 'generate'){

            // If the generate link then create the password variable from the generator function
            password = $.password(12,true);

            // Empty the random tag then append the password and fade In
            $('#random').hide().append(password).fadeIn('slow');

            // Also fade in the confirm link
            $('#confirm').fadeIn('slow');
        } else {
            // If the confirm link is clicked then input the password into our form field
            $('#input-password').val(password);
            // remove password from the random tag
            $('#random').empty();
            // Hide the confirm link again
            $(this).hide();
        }
        e.preventDefault();
    });
});
</pre>
<p>The function is fairly simple. The hide() and fadeIn() isnt essential &#8211; you can just append the new password to the #random selector but we added the fadeIn to make it a little more &#8216;exciting&#8217;!</p>
<p>The final e.preventDefault() stops the browser jumping to the top of the screen when the generate and confirm links are clicked.</p>
<p>To change the password length set the first option in the password function to the required number of characters. The second option takes a boolean value and sets whether special characters are to be used in the password.</p>
<p><a href="/lab/jquery/demo/jquery_demo_password_generator.htm" class="demo">See Random Password Demo</a> <a href="/lab/jquery/demo/download/jquery_demo_password_generator.zip" class="demo">Download the source code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/random-password-generator-using-jquery/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>jQuery Plugin &#8211; Drill Down Menu</title>
		<link>http://www.designchemical.com/blog/index.php/jquery-plugins/jquery-plugin-drill-down-menu/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery-plugins/jquery-plugin-drill-down-menu/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 14:36:58 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jQuery Plugins]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[slider]]></category>
		<category><![CDATA[vertical]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=1339</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery-plugins/jquery-plugin-drill-down-menu/"><img align="left" hspace="5" width="150" src="http://www.designchemical.com/blog/wp-content/plugins/thumbnail-for-excerpts/jquery_code.png" class="alignleft wp-post-image tfe" alt="" title="" /></a><p>Following the release of our new WordPress plugin &#8211; jQuery Drill Down iPod Menu Widget we have now also set up the jQuery plugin code that was used to create the WordPress widget.</p>
<p>Drill down menus are perfect for arranging and managing complex nested menus in compact and fixed sized areas and provide excellent useability where standard drop down menus &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery-plugins/jquery-plugin-drill-down-menu/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>Following the release of our new <a href="/blog/index.php/wordpress-plugins/wordpress-plugin-jquery-drill-down-ipod-menu-widget/">WordPress plugin &#8211; jQuery Drill Down iPod Menu Widget</a> we have now also set up the jQuery plugin code that was used to create the WordPress widget.</p>
<p>Drill down menus are perfect for arranging and managing complex nested menus in compact and fixed sized areas and provide excellent useability where standard drop down menus may be too awkward.</p>
<p>The plugin converts standard hierarchical nested HTML into drill down (iPod style) menus. Features of the drill down menu plugin include – saved state using cookies, add count of total number of child links to each menu option and offers 3 different ways to navigate the menu</p>
<p>Check out our <a href="/lab/jquery-drill-down-menu-plugin/getting-started/">jQuery Drill Down Menu</a> project pages for more information, drill down menu examples and to download the plugin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery-plugins/jquery-plugin-drill-down-menu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress Tutorial &#8211; Adding A Widget Area To Your Theme Files</title>
		<link>http://www.designchemical.com/blog/index.php/wordpress-tips/wordpress-tutorial-adding-a-widget-area-to-your-theme-files/</link>
		<comments>http://www.designchemical.com/blog/index.php/wordpress-tips/wordpress-tutorial-adding-a-widget-area-to-your-theme-files/#comments</comments>
		<pubDate>Wed, 23 Feb 2011 09:55:34 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[Wordpress Plugins]]></category>
		<category><![CDATA[Wordpress Tips]]></category>
		<category><![CDATA[accordion]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=1265</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/wordpress-tips/wordpress-tutorial-adding-a-widget-area-to-your-theme-files/"><img align="left" hspace="5" width="150" src="http://www.designchemical.com/blog/wp-content/plugins/thumbnail-for-excerpts/jquery_code.png" class="alignleft wp-post-image tfe" alt="" title="" /></a><p>Following up to the 2 recent WordPress menu plugins we launched we thought we should do a quick tutorial on how to add a widget area to your WordPress theme.</p>
<p>Both of the plugins, the jQuery Mega Menu and the jQuery Vertical Accordion Menu use widget areas as a quick and easy way to add custom menus to your WordPress &#8230; <a href="http://www.designchemical.com/blog/index.php/wordpress-tips/wordpress-tutorial-adding-a-widget-area-to-your-theme-files/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>Following up to the 2 recent WordPress menu plugins we launched we thought we should do a quick tutorial on how to add a widget area to your WordPress theme.</p>
<p>Both of the plugins, the <a href="/blog/index.php/wordpress-plugins/wordpress-plugin-jquery-drop-down-mega-menu-widget/">jQuery Mega Menu</a> and the <a href="/blog/index.php/wordpress-plugins/wordpress-plugin-jquery-vertical-accordion-menu-widget/">jQuery Vertical Accordion Menu</a> use widget areas as a quick and easy way to add custom menus to your WordPress site. If your theme does not have widget areas already set up in the locations where you need the menu then you need to create a new one in your theme files.</p>
<p>Its a fairly simple process, which involves 2 steps:</p>
<h3>1. Register The Widget</h3>
<p>To register the new widget you need to open the functions.php file in your WordPress themes editor.</p>
<p>Add the following code to the functions file, making sure you place it in between php tags:</p>
<pre class="brush: php; title: ; notranslate">
if ( function_exists('register_sidebar') ){
    register_sidebar(array(
        'name' =&gt; 'my_mega_menu',
        'before_widget' =&gt; '&lt;div id=&quot;my-mega-menu-widget&quot;&gt;',
        'after_widget' =&gt; '&lt;/div&gt;',
        'before_title' =&gt; '',
        'after_title' =&gt; '',
));
}
</pre>
<p>Give the widget area a name &#8211; e.g. my_mega_menu and in the before/after options you can place code which you wish to appear wrapped around either the widget itself or the title.</p>
<p>Since we are wanting to use one of the menu widget themes, which come with plugins we dont want to wrap it in the standard widget tags, which may interfere with the CSS.</p>
<p>For this example we have just wrapped it in a div tag with the id &#8211; my-mega-menu-widget.</p>
<h3>2. Add The Widget Code To Your Theme</h3>
<p>Now we can add the code that will call the widget to the correct location in our theme files. Since we are creating a horizontal mega menu we obviously want to display this in the header.</p>
<p>In your WordPress themes editor open the header.php file.</p>
<p>Find the location where you want to place the menu and add the following code to the header.php file:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php /* Widgetized sidebar */
    if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('my_mega_menu') ) : ?&gt;&lt;?php endif; ?&gt;
</pre>
<p>Make sure that you change the &#8220;my_mega_menu&#8221; text to be the same as the name you gave to your widget area in the functions file.</p>
<p>Save the changes to the header.php file</p>
<p>If you now go to the widget area in WordPress admin you should see a new widget area in the right hand column with the name of your widget.</p>
<p>You can now add your mega menu, accordion menu or any other widget to this area.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/wordpress-tips/wordpress-tutorial-adding-a-widget-area-to-your-theme-files/feed/</wfw:commentRss>
		<slash:comments>185</slash:comments>
		</item>
		<item>
		<title>Create An Image Preloader For Image Swap Using jQuery</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/create-image-preloader-image-swap-function-jquery/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/create-image-preloader-image-swap-function-jquery/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 14:42:53 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[images]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=1215</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/create-image-preloader-image-swap-function-jquery/"><img align="left" hspace="5" width="150" src="http://www.designchemical.com/blog/wp-content/plugins/thumbnail-for-excerpts/jquery_code.png" class="alignleft wp-post-image tfe" alt="" title="" /></a><p>The following tutorial takes one of our earlier code snippets and improves it by adding a function to preload images.</p>
<p>The Quick and Easy jQuery Image Swap function offers a very simple way of implementing image change on hover for buttons, links, etc (see earlier post for more info). One problem however is that the first time the active image &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/create-image-preloader-image-swap-function-jquery/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>The following tutorial takes one of our earlier code snippets and improves it by adding a function to preload images.</p>
<p>The <a href="http://www.designchemical.com/blog/index.php/jquery/quick-and-easy-jquery-image-swap/">Quick and Easy jQuery Image Swap</a> function offers a very simple way of implementing image change on hover for buttons, links, etc (see earlier post for more info). One problem however is that the first time the active image is called for a page there tends to be a delay as the new image loads.</p>
<p>One way to overcome this problem and ensure that the image swaps are more responsive is to preload all active versions of the images when the page downloads.</p>
<p class="clear">There are 2 parts to our jQuery code:</p>
<ul class="content-list">
<li>First we create our preload function, which will take an array of image file names and preload them when the page loads.</li>
<li>Then we create a function to create the image array by selecting all relevant images &#8211; i.e. the ones to be used in our image swap function. After selecting the images we then change the file names to those of the active images &#8211; i.e. swap &#8220;_off&#8221; for &#8220;_on&#8221; and store them in the array. This array can then be passed to the preload function.</li>
</ul>
<h3>1. jQuery Code &#8211; Preload Function</h3>
<pre class="brush: jscript; title: ; notranslate">
$.fn.preload = function() {
    this.each(function(){
        $('&lt;img/&gt;')[0].src = this;
    });
}
</pre>
<h3>2. jQuery Code To Create The Image Array</h3>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function() {
    // Declare the array variable
    var imgSwap = [];
    // Select all images used in the image swap function - in our case class &quot;img-swap&quot;
    $(&quot;.img-swap&quot;).each(function(){
        // Loop through all images which are used in our image swap function
        // Get the file name of the active images to be loaded by replacing _off with _on
        imgUrl = this.src.replace(&quot;_off&quot;,&quot;_on&quot;);
        // Store the file name in our array
        imgSwap.push(imgUrl);
    });
    // Pass the array to our preload function
    $(imgSwap).preload();
});
</pre>
<p>That&#8217;s basically it &#8230; a few lines of code, which will greatly enhance the performance of the image swap fuction.</p>
<p>In the following demo you can see the difference between a set of buttons using preload vs ones loading on hover:</p>
<p><a href="/lab/jquery/demo/jquery_image_swap_preload.htm" class="demo">Check Out The Preload Demo</a> <a href="/lab/jquery/demo/download/jquery_image_swap_preloader.zip" class="demo">Download Source Code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/create-image-preloader-image-swap-function-jquery/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Create Your Own jQuery AJAX Form Submit With Validation</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/create-your-own-jquery-ajax-form-submit-with-validation/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/create-your-own-jquery-ajax-form-submit-with-validation/#comments</comments>
		<pubDate>Thu, 03 Feb 2011 23:42:04 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Validation]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=1149</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/create-your-own-jquery-ajax-form-submit-with-validation/"><img align="left" hspace="5" width="150" src="http://www.designchemical.com/blog/wp-content/plugins/thumbnail-for-excerpts/jquery_code.png" class="alignleft wp-post-image tfe" alt="" title="" /></a><p>For today&#8217;s tutorial we are going to do something a little more interesting and take several jQuery functions, which have been covered in our previous posts and combine them to create our own form submit process, which will be able to handle all of the forms in our projects.</p>
<p>This is a good exercise to see how various components/snippets can &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/create-your-own-jquery-ajax-form-submit-with-validation/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>For today&#8217;s tutorial we are going to do something a little more interesting and take several jQuery functions, which have been covered in our previous posts and combine them to create our own form submit process, which will be able to handle all of the forms in our projects.</p>
<p>This is a good exercise to see how various components/snippets can be combined to create a complete function.</p>
<p>The tutorial assumes you have the basic understanding of the HTML and CSS for the form.</p>
<p><a href="/lab/jquery/demo/jquery_ajax_form_submit_with_validation.htm" class="demo">View Demo</a><a href="http://www.designchemical.com/lab/jquery/demo/download/jquery_ajax_form_submit_with_validation.zip" class="demo">Download Source Files</a></p>
<h3 class="clear"><strong>The Basic Components</strong></h3>
<p>So, in order to create our process we are going to use the following components:</p>
<ol>
<li>A general HTML form format</li>
<li>Our standard CSS rules for styling the form</li>
<li>Add default text for our input fields, including a function to remove the default text when the form is submitted &#8211; see earlier blog post &#8211; <a href="http://www.designchemical.com/blog/index.php/jquery/add-default-text-to-form-fields-using-jquery/">Add Default Text To Form Fields Using jQuery</a></li>
<li>jQuery validation rules, which are applied when a form is submitted</li>
<li>jQuery code for processing the form and submitting the contents via AJAX</li>
</ol>
<h3><strong>1. HTML Form Format</strong></h3>
<p>Obviously everyone has their own preferences when it comes to how you code your form. After experimenting with several different formats I found that using an ordered list to handle the layout, which each form input field and associated label being one list item, has been easiest to use and so far has been robust enough to take most standard form requirements.</p>
<p>For the tutorial we will create a standard contact form with a name field, email, telephone and text area for comments:</p>
<pre class="brush: plain; title: ; notranslate">
&lt;form id=&quot;form-contact&quot; class=&quot;styled&quot; action=&quot;/user_functions.php&quot; method=&quot;post&quot;&gt;
		    &lt;fieldset&gt;
			  &lt;legend&gt;Contact Form&lt;/legend&gt;
			  &lt;ol&gt;
			    &lt;li class=&quot;form-row&quot;&gt;
				  &lt;label&gt;Email:&lt;/label&gt;
				  &lt;input id=&quot;input-email&quot; type=&quot;text&quot; class=&quot;text-input required email default&quot; name=&quot;email&quot; value=&quot;&quot; title=&quot;Enter Your Email Address&quot; /&gt;
				&lt;/li&gt;
				&lt;li class=&quot;form-row&quot;&gt;
				  &lt;label&gt;Name:&lt;/label&gt;
				  &lt;input id=&quot;input-name&quot; type=&quot;text&quot; class=&quot;text-input required default&quot; name=&quot;name&quot; value=&quot;&quot; title=&quot;Enter Your Full Name&quot; /&gt;
				&lt;/li&gt;
				&lt;li class=&quot;form-row&quot;&gt;
				  &lt;label&gt;Phone:&lt;/label&gt;
				  &lt;input id=&quot;input-phone&quot; type=&quot;text&quot; class=&quot;text-input&quot; name=&quot;phone&quot; value=&quot;&quot; /&gt;
				&lt;/li&gt;
				&lt;li class=&quot;form-row&quot;&gt;
				  &lt;label&gt;Comments:&lt;/label&gt;
				  &lt;textarea id=&quot;input-message&quot; class=&quot;text-area&quot; name=&quot;message&quot; cols=&quot;40&quot; rows=&quot;8&quot;&gt;&lt;/textarea&gt;
				&lt;/li&gt;
				&lt;li class=&quot;button-row text-right&quot;&gt;
				  &lt;input class=&quot;btn-submit&quot; type=&quot;submit&quot; value=&quot;submit&quot; name=&quot;submit&quot; /&gt;
				&lt;/li&gt;
			  &lt;/ol&gt;
			&lt;/fieldset&gt;
		  &lt;/form&gt;
</pre>
<p>As usual our jQuery will use css classes and IDs for the selectors. The key ones we need to include are:</p>
<ul class="content-list">
<li>Class &#8220;<strong>btn-submit</strong>&#8221; on the form submit button &#8211; used to trigger the function.</li>
<li>Class &#8220;<strong>required</strong>&#8221; on any input fields to be validated.</li>
<li>Class &#8220;<strong>email</strong>&#8221; as an additional class on those input fields to be tested against our regular expression for correctly formatted email addressed.</li>
</ul>
<h3><strong>2. The Form CSS</strong></h3>
<p>The CSS I use as the basis for this format is as follows:</p>
<pre class="brush: plain; title: ; notranslate">
.styled {
font-family: Arial, sans-serif;
}
.styled fieldset {
border: 1px solid #ccc; padding: 10px;
}
.styled fieldset legend {
font-size: 16px; font-weight: bold; color: #000; text-transform: capitalize; padding: 5px; background: #fff; display: block; margin-bottom: 0; border: 1px solid #ccc;
}
.styled fieldset ol, .styled fieldset ol li {
list-style: none;
}
.styled fieldset li.form-row {
margin-bottom: 3px; padding: 2px 0; width: 100%; overflow: hidden; position: relative;
}
.styled label {
font-size: 12px; display: block; font-weight: bold; float: left; width: 100px; margin-left: 5px; line-height: 24px;
}
.styled input.text-input, .styled .text-area {
background: #fefefe; border-top: 1px solid #909090; border-right: 1px solid #cecece; border-bottom: 1px solid #e1e1e1; border-left: 1px solid #bbb; padding: 3px; width: 220px; font-size: 12px;
}
.styled input.text-input.default.active, .styled .text-area.default.active {
color: #666; font-style: italic;
}
.styled fieldset li.button-row {
margin-bottom: 0; padding: 2px 5px;
}
form input.btn-submit {
padding: 3px 7px; border: 1px solid #fff; background: #066CAA; font-size: 12px;
}
</pre>
<p>This is pretty much the minimum styling we need to add to get the labels and input fields aligned and pad/border the form. This can then be applied to your forms by adding the class &#8220;styled&#8221;. You can build on the above CSS to make your forms a little more exciting!</p>
<p>Any specific rules you may want to add for each form can be done using it&#8217;s id. For our contact form #form-contact, we want to set the width to 320px and center on the page.</p>
<h3><strong>Validation CSS</strong></h3>
<p>In addition to the form layout we also need a few additional CSS rules, which will handle the styling of the validation results:</p>
<pre class="brush: plain; title: ; notranslate">
.styled span.error {
font-size: 11px; position: absolute; top: 0; right: 0; display: block; padding: 2px;
}
.styled fieldset li.error {
color: #D8000C; background: #fff0f0 url(../media/images/checkers.png) repeat; border: 1px solid #f9c7c7; padding: 5px 0;
}
.styled fieldset li.error label {
text-align: left;
}
</pre>
<h3><strong>3. The jQuery Code &#8211; Default Text Function</strong></h3>
<p>Before we tackle the form submission and validation lets add the jQuery code to handle the default text for the input fields &#8211; <a href="http://www.designchemical.com/blog/index.php/jquery/add-default-text-to-form-fields-using-jquery/">See earlier post for explanation</a>.</p>
<pre class="brush: jscript; title: ; notranslate">
$(&quot;.default&quot;).each(function(){
  var defaultVal = $(this).attr('title');
  $(this).focus(function(){
    if ($(this).val() == defaultVal){
      $(this).removeClass('active').val('');
    }
  });
  $(this).blur(function() {
    if ($(this).val() == ''){
      $(this).addClass('active').val(defaultVal);
    }
  })
  .blur().addClass('active');
});
</pre>
<p>We can now add default text to any of our form fields by simply adding the class &#8220;default&#8221; and using the title attribute to hold the default text. In our contact form example we have decided to add default text to both the email fields and the name field, which are both required.</p>
<p>Since we dont want the default text to be submitted with the form for any empty fields we add a jQuery function, which will automatically check all input fields with class &#8220;default&#8221; and remove the text if the value is the same as the title attribute:</p>
<pre class="brush: jscript; title: ; notranslate">
function defaulttextRemove(){
  $('.default').each(function(){
    var defaultVal = $(this).attr('title');
    if ($(this).val() == defaultVal){
      $(this).val('');
    }
  });
}
</pre>
<p>Now for our main function, handling the form submit. There are a few parts to this process:</p>
<ol>
<li>Check the form details &#8211; i.e. exactly which submit button has been pressed and the action URL for the data, since we are creating a generic function, which can be used by any forms, including multiple instances on one page.</li>
<li>Run the relevant validation on all required input fields &#8211; for our example we have both standard required text field and email validation using regular expressions to check for a correct email format.</li>
<li>Assuming no errors, we serialize the form data and using AJAX, post the contents to the form URL and return a result.</li>
</ol>
<div class="banner-horizontal">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-7740611438413740";
/* Banner Mid Post */
google_ad_slot = "8625321051";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<h3><strong>4. Form Validation and AJAX Form Submit jQuery Code</strong></h3>
<pre class="brush: jscript; title: ; notranslate">
// Declare the loading gif as a variable, which will be used later
var $loading = $('&lt;div class=&quot;loading&quot;&gt;&lt;img src=&quot;/media/images/loading.gif&quot; alt=&quot;&quot; /&gt;&lt;/div&gt;');

// Form validation and submit when button is clicked
$('.btn-submit').click(function(e){

  // Declare the function variables - parent form, form URL and the regex for checking the email
     var $formId = $(this).parents('form');
     var formAction = $formId.attr('action');
     var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

  // In preparation for validating the form - Remove any active default text and previous errors
      defaulttextRemove();
      $('li',$formId).removeClass('error');
      $('span.error').remove();

  // Start validation by selecting all inputs with the class &quot;required&quot;
      $('.required',$formId).each(function(){
          var inputVal = $(this).val();
          var $parentTag = $(this).parent();
          if(inputVal == ''){
              $parentTag.addClass('error').append('&lt;span class=&quot;error&quot;&gt;Required field&lt;/span&gt;');
          }

      // Run the email validation using the regex for those input items also having class &quot;email&quot;
	  if($(this).hasClass('email') == true){
              if(!emailReg.test(inputVal)){
                  $parentTag.addClass('error').append('&lt;span class=&quot;error&quot;&gt;Enter a valid email address.&lt;/span&gt;');
              }
          }
    });

    // All validation complete - check whether any errors exist - if not submit form
       if ($('span.error').length == &quot;0&quot;) {
           $formId.append($loading.clone());
           $('fieldset',$formId).hide();
           $.post(formAction, $formId.serialize(),function(data){
               $('.loading').remove();
               $formId.append(data).fadeIn();
           });
      }
    // Use the following to prevent the form being submitted the standard way
      e.preventDefault();
});
</pre>
<p>When the submit button is clicked all input fields with the class &#8220;required&#8221; are checked to see if they have a value. If not an error class is applied to the parent list tag (allows us to highlight the complete form row) as well as an error text message inserted after the input field.</p>
<p>If the input field also has the class &#8220;email&#8221; a further validation check is made using a standard regular expression to see if the text pattern matches that of an email format.</p>
<p>If any of the validation checks return an error then the form submit is stopped. Here we use an extremely easy and effective way of seeing if there are any errors by using $(&#8216;span.error&#8217;).length. If length is not &#8220;0&#8243; then there are error messages still active.</p>
<p>If all validation is clear we then use the $.post function to submit the form data. At the same time we hide the form contents and replace with a loading gif.</p>
<p>When the data is returned from the AJAX post we then hide the loading gif and replace the form contents with the data itself &#8211; usually this would be something like a status message for the user.</p>
<h3><strong>The Complete jQuery Code</strong></h3>
<pre class="brush: jscript; title: ; notranslate">
jQuery(document).ready(function($) {
	var $loading = $('&lt;div class=&quot;loading&quot;&gt;&lt;img src=&quot;/media/images/loading.gif&quot; alt=&quot;&quot; /&gt;&lt;/div&gt;');
	$(&quot;.default&quot;).each(function(){
		var defaultVal = $(this).attr('title');
		$(this).focus(function(){
			if ($(this).val() == defaultVal){
				$(this).removeClass('active').val('');
			}
		});
		$(this).blur(function() {
			if ($(this).val() == ''){
				$(this).addClass('active').val(defaultVal);
			}
		})
		.blur().addClass('active');
	});
	$('.btn-submit').click(function(e){
		var $formId = $(this).parents('form');
		var formAction = $formId.attr('action');
		defaulttextRemove();
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		$('li',$formId).removeClass('error');
		$('span.error').remove();
		$('.required',$formId).each(function(){
			var inputVal = $(this).val();
			var $parentTag = $(this).parent();
			if(inputVal == ''){
				$parentTag.addClass('error').append('&lt;span class=&quot;error&quot;&gt;Required field&lt;/span&gt;');
			}
			if($(this).hasClass('email') == true){
				if(!emailReg.test(inputVal)){
					$parentTag.addClass('error').append('&lt;span class=&quot;error&quot;&gt;Enter a valid email address.&lt;/span&gt;');
				}
			}
		});
		if ($('span.error').length == &quot;0&quot;) {
			$formId.append($loading.clone());
			$('fieldset',$formId).hide();
			$.post(formAction, $formId.serialize(),function(data){
				$('.loading').remove();
				$formId.append(data).fadeIn();
			});
		}
		e.preventDefault();
	});
});
function defaulttextRemove(){
	$('.default').each(function(){
		var defaultVal = $(this).attr('title');
		if ($(this).val() == defaultVal){
			$(this).val('');
		}
	});
}
</pre>
<p><a href="/lab/jquery/demo/jquery_ajax_form_submit_with_validation.htm" class="demo">View Demo</a></p>
<p><a href="http://www.designchemical.com/lab/jquery/demo/download/jquery_ajax_form_submit_with_validation.zip" class="demo">Download Source Files</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/create-your-own-jquery-ajax-form-submit-with-validation/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Setting Equal Heights of Floated Elements Using jQuery</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/setting-equal-heights-of-floated-elements-using-jquery/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/setting-equal-heights-of-floated-elements-using-jquery/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 19:53:15 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Design Tips]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=1123</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/setting-equal-heights-of-floated-elements-using-jquery/"><img align="left" hspace="5" width="150" src="http://www.designchemical.com/blog/wp-content/uploads/2011/01/no_resize.png" class="alignleft wp-post-image tfe" alt="no_resize" title="no_resize" /></a><p>As a web designer you are bound to come across the problem of how to handle unequal heights of floated elements, especially when it comes to layouts for online stores:</p>
Without Resizing
<p class="text-center"><img src="http://www.designchemical.com/blog/wp-content/uploads/2011/01/no_resize.png" alt="no_resize" title="no_resize" width="400" height="473" class="size-full wp-image-1124" /></p>
<p>Whilst many ecommerce/content management systems will automatically create standard thumbnails or you can use CSS to limit the height of the thumbnail shown sometimes it is &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/setting-equal-heights-of-floated-elements-using-jquery/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>As a web designer you are bound to come across the problem of how to handle unequal heights of floated elements, especially when it comes to layouts for online stores:</p>
<h3 class="margin-bottom text-center">Without Resizing</h3>
<p class="text-center"><img src="http://www.designchemical.com/blog/wp-content/uploads/2011/01/no_resize.png" alt="no_resize" title="no_resize" width="400" height="473" class="size-full wp-image-1124" /></p>
<p>Whilst many ecommerce/content management systems will automatically create standard thumbnails or you can use CSS to limit the height of the thumbnail shown sometimes it is not possible/desirable/liked by client to limit the thumbnail height.</p>
<p>Using jQuery we can easily overcome this problem to create an auto-resizing product list:</p>
<h3 class="margin-bottom text-center">Using jQuery to Resize</h3>
<p class="text-center"><img src="http://www.designchemical.com/blog/wp-content/uploads/2011/01/jquery_resize.png" alt="jquery_resize" title="jquery_resize" width="400" height="371" class="size-full wp-image-1128" /></p>
<h3>The jQuery Code:</h3>
<p>So, in the following jQuery code we are going to do a few things:</p>
<ol>
<li>Create a function to determine the greatest height of an element</li>
<li>Use the above function to get the height of the largest list item</li>
<li>Use the function again to get the height of the largest image</li>
<li>Use the above values to then set the CSS of the list item &#8211; for this example we set both the height of the list item as well as the bottom margin of the image to line-up the text</li>
</ol>
<pre class="brush: jscript; title: ; notranslate">
// The function to find the greatest height from a set of elements
function findMaxValue(element){
    var maxValue = undefined;
    $(element).each(function(){
        var val = parseInt($(this).height());
        if (maxValue === undefined || maxValue &lt; val) {
            maxValue = val;
        }
    });
    return maxValue;
}
// Using the above function we set the height of all list items and the bottom margin of the image
$(document).ready(function (){
    $listItem = $('ul li');
    maxValue = findMaxValue($listItem);
    $listItemImg = $('img',$listItem);
    maxImgHeight = findMaxValue($listItemImg);
    $listItem.each(function(){
        $(this).css(&quot;height&quot;,maxValue);
        var imageHeight = $('img',this).height();
        var imageMargin = maxImgHeight - imageHeight;
       $('img',this).css(&quot;margin-bottom&quot;,imageMargin);
    });
});
</pre>
<p>Whilst we have used a list of thumbnails and text to demonstrate the jQuery this can easily be applied to an selection of elements.</p>
<p><a href="http://www.designchemical.com/lab/jquery/demo/jquery_demo_set_equal_heights.htm" class="demo">View Demo &#8211; Set Equal Heights Using jQuery</a> <a href="http://www.designchemical.com/lab/jquery/demo/download/jquery_demo_set_equal_heights.zip" class="demo">Download source files</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/setting-equal-heights-of-floated-elements-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Tutorial Demos</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/jquery-tutorial-demos/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/jquery-tutorial-demos/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 17:14:07 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tools & Resources]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=1120</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/jquery-tutorial-demos/"><img align="left" hspace="5" width="150" src="http://www.designchemical.com/blog/wp-content/plugins/thumbnail-for-excerpts/jquery_code.png" class="alignleft wp-post-image tfe" alt="" title="" /></a><p>I have now added a list of all of the available jQuery tutorial demos so far, including demos and links for the jQuery plugins. So if you are looking for some quick tips take a look at:</p>
<p>jQuery Tutorial Demos</p>
]]></description>
			<content:encoded><![CDATA[<p>I have now added a list of all of the available jQuery tutorial demos so far, including demos and links for the jQuery plugins. So if you are looking for some quick tips take a look at:</p>
<p><a href="http://www.designchemical.com/lab/jquery/demo/jquery_demo_list.htm" class="demo">jQuery Tutorial Demos</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/jquery-tutorial-demos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Light-Weight jQuery Animated Slider</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/light-weight-jquery-animated-slider/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/light-weight-jquery-animated-slider/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 21:56:25 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[slider]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=1103</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/light-weight-jquery-animated-slider/"><img align="left" hspace="5" width="150" src="http://www.designchemical.com/blog/wp-content/plugins/thumbnail-for-excerpts/jquery_code.png" class="alignleft wp-post-image tfe" alt="" title="" /></a><p>Today&#8217;s tutorial is a brief look at the jQuery animate function and how this can be used to create a very quick and easy content slider from an unordered list and a few lines of jQuery.</p>
<p>Whilst there are a lot of plugins out there for creating slick jQuery sliders sometimes all you need is a few lines a code &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/light-weight-jquery-animated-slider/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s tutorial is a brief look at the jQuery animate function and how this can be used to create a very quick and easy content slider from an unordered list and a few lines of jQuery.</p>
<p>Whilst there are a lot of plugins out there for creating slick jQuery sliders sometimes all you need is a few lines a code to come up with your own features and in fact this simple code snippet is only 580 bytes!</p>
<p><a href="http://www.designchemical.com/lab/jquery/demo/jquery_demo_light_weight_animated_slider.htm" class="demo">View the jQuery light weight slider demo</a></p>
<p><a href="http://www.designchemical.com/lab/jquery/demo/download/jquery_demo_light_weight_animated_slider.zip" class="demo">Download source files</a></p>
<h3 class="clear"><strong>The HTML Code</strong></h3>
<p>The slider will be created from a very simple unordered list, which we wrap in a container tag. The jQuery will automatically handle any number of list items so we can add as many as necessary. Since its created from straight forward HTML our slider can contain any content including text, images, etc:</p>
<pre class="brush: plain; title: ; notranslate">
&lt;div id=&quot;light-slide&quot;&gt;
  &lt;ul&gt;
    &lt;li&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas pharetra, elit sed hendrerit condimentum, libero elit tincidunt mauris, id rutrum tellus leo at urna. Fusce dui mi, lacinia sit amet blandit vitae, interdum ut eros.&lt;/li&gt;
    &lt;li&gt;Aenean scelerisque ipsum a nunc placerat sed blandit odio sollicitudin. Donec sed velit id ipsum lobortis tincidunt a sit amet leo. Praesent sit amet nisl a arcu lobortis egestas. Nunc at felis in erat condimentum ornare vel vel nisl.&lt;/li
    &lt;li&gt;Suspendisse iaculis sodales dui pretium faucibus. Praesent vitae ipsum justo, id tempor tellus. In nulla leo, dignissim quis luctus sed, commodo nec velit. Aliquam ac nisl quam, quis tincidunt magna.&lt;/li&gt;
    &lt;li&gt;It elit sed hendrerit condimentum, libero elit tincidunt mauris, id rutrum tellus leo at urna. Fusce dui mi, lacinia sit amet blandit vitae, interdum ut eros. Nulla egestas imperdiet rutrum. Praesent vel metus ligula.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</pre>
<p>So, in our example we have 4 list items, all wrapped in a div tag, which has the id &#8220;light-slide&#8221;.</p>
<h3><strong>The jQuery Code</strong></h3>
<p>The jQuery basically comes in 2 parts &#8211; the first section creates the control navigation buttons for our content slider and the second part handles the animation function when we click a control button:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function (){

  // Here we check how many list items are present and generate the correspdonding number of control buttons //
    var controlHtml = '&lt;div id=&quot;control&quot;&gt;';
    $('#light-slide li').each(function(){
        controlHtml += '&lt;a href=&quot;#&quot;&gt;&lt;/a&gt;';
    });
    controlHtml += '&lt;/div&gt;';
    $('#light-slide').after(controlHtml);

  // Set the first button to &quot;active&quot; //
  $('#control a:first').addClass('active');

  // Next we define the click event and subsequent animate function that will move our slider to the correct position //
  var $slideButton = $('#control a');
  $slideButton.click(function(e){
      $slideButton.removeClass('active');
      $(this).addClass('active');
      var integer = $(this).index();
      $('#light-slide ul').animate({&quot;left&quot;: -400*integer}, 400);
      e.preventDefault();
    });
});
</pre>
<p>So in the above code, when one of the slider buttons is clicked the jQuery code checks the position of the button using index() and moves the unordered list sideways based on the list position x the list item width &#8211; in this case 400px. So if we click button #3 our list will be moved 800 pixels to the left, therefore showing slide number 3 in the viewing area.</p>
<h3><strong>The CSS</strong></h3>
<p>There are a few CSS rules, which are essential for the jQuery to be effective:</p>
<pre class="brush: plain; title: ; notranslate">
/* The slider container width needs to be fixed based on the width of one of our list items and the overflow set to &quot;hidden&quot; to hide the other items */
#light-slide {width: 400px; height: 200px; overflow: hidden; position: relative;}
#light-slide ul {height: 200px; position: absolute; top: 0; left: 0;}

/* We set the width and the height of each list item to match the slider container */
#light-slide li {width: 400px; height: 200px; float: left;}

/* The following code just sets the control button styling */
#control a {background:#999;padding:6px;display:block;float:left;margin-right:5px;}
#control a.active{background:#111;padding:6px;display:block;float:left;outline:none;}
</pre>
<p>And that is basically it &#8230;</p>
<p><a href="http://www.designchemical.com/lab/jquery/demo/jquery_demo_light_weight_animated_slider.htm" class="demo">View the jQuery light weight slider demo</a></p>
<p><a href="http://www.designchemical.com/lab/jquery/demo/download/jquery_demo_light_weight_animated_slider.zip" class="demo">Download source files</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/light-weight-jquery-animated-slider/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Add Default Text To Form Fields Using jQuery</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/add-default-text-to-form-fields-using-jquery/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/add-default-text-to-form-fields-using-jquery/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 07:28:57 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=1056</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/add-default-text-to-form-fields-using-jquery/"><img align="left" hspace="5" width="120" height="120" src="http://www.designchemical.com/blog/wp-content/uploads/2010/05/thumb_jquery_code.png" class="alignleft tfe wp-post-image" alt="thumb_jquery_code" title="thumb_jquery_code" /></a><p>The following code snippet is a handy jQuery function that will allow you to add default text to any form input text field using the element&#8217;s title attribute.</p>
<p>View Default Text Demo.</p>
1. The HTML &#8211; Form With Text Inputs
<p>So, in the above example we have created a very basic form with 3 text input fields and a submit &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/add-default-text-to-form-fields-using-jquery/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>The following code snippet is a handy jQuery function that will allow you to add default text to any form input text field using the element&#8217;s title attribute.</p>
<p><a href="http://www.designchemical.com/lab/jquery/demo/jquery_form_input_default_text.htm" class="demo">View Default Text Demo</a>.</p>
<h3 class="clear">1. The HTML &#8211; Form With Text Inputs</h3>
<pre class="brush: plain; title: ; notranslate">
&lt;form action=&quot;&quot; method=&quot;get&quot;&gt;
    &lt;div&gt;&lt;input type=&quot;text&quot; name=&quot;text1&quot; value=&quot;&quot; class=&quot;default&quot; title=&quot;Default Text 1&quot; /&gt;&lt;/div&gt;
    &lt;div&gt;&lt;input type=&quot;text&quot; name=&quot;text2&quot; value=&quot;&quot; class=&quot;default&quot; title=&quot;Default Text 2&quot; /&gt;&lt;/div&gt;
    &lt;div&gt;&lt;input type=&quot;text&quot; name=&quot;text3&quot; value=&quot;&quot; class=&quot;default&quot; title=&quot;Default Text 3&quot; /&gt;&lt;/div&gt;
    &lt;div&gt;&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;submit&quot; id=&quot;submit&quot; /&gt;&lt;/div&gt;
&lt;/form&gt;
</pre>
<p>So, in the above example we have created a very basic form with 3 text input fields and a submit button. For each of the text inputs we have added the class &#8220;default&#8221;, which we will use in the jQuery function to identify the input fields and a title attribute, which contains the default text that we wish to display.</p>
<h3>2. JQuery Code Part I &#8211; Creating The Default Text</h3>
<p>For the first part of the function we add code, which will take the title attribute of each input field with the class &#8220;default&#8221; and insert this in the form field:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function(){
  $('.default').each(function(){
    var defaultVal = $(this).attr('title');
    $(this).focus(function(){
      if ($(this).val() == defaultVal){
        $(this).removeClass('active').val('');
      }
    })
    .blur(function(){
      if ($(this).val() == ''){
        $(this).addClass('active').val(defaultVal);
      }
    })
    .blur().addClass('active');
  });
});
</pre>
<p>There are 2 parts to the function:</p>
<p><strong>On Focus</strong><br />
jQuery checks the actual input value and if it is the same as the default text (i.e. no input has yet been made) it will clear the form field and remove the &#8220;active&#8221; class, basically resetting the text field for the user to enter their text.</p>
<p><strong>On Blur</strong><br />
jQuery checks the input value and if it is empty it will apply the default text from the title attribute and add the active class, which we can use for the default text styling.</p>
<h3>3. JQuery Code Part II &#8211; Handling Form Submit</h3>
<p>When the form is submitted we obviously dont want the default text submitted for any text elements that may have been left blank by the user. We can handle this using the following jQuery function:</p>
<pre class="brush: jscript; title: ; notranslate">
$('form').submit(function(){
  $('.default').each(function(){
    var defaultVal = $(this).attr('title');
    if ($(this).val() == defaultVal){
      $(this).val('');
    }
  });
});
</pre>
<p>The above code checks each input element with the class &#8220;default&#8221; and if the form field value is the same as the title attribute it will clear the text prior to the form being submitted.</p>
<h3>4. The Complete jQuery Code</h3>
<p>The following is the complete jQuery code for both the default text and handling the form submit:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function(){
  $('.default').each(function(){
    var defaultVal = $(this).attr('title');
    $(this).focus(function(){
      if ($(this).val() == defaultVal){
        $(this).removeClass('active').val('');
      }
    })
    .blur(function(){
      if ($(this).val() == ''){
        $(this).addClass('active').val(defaultVal);
      }
    })
    .blur().addClass('active');
  });
  $('form').submit(function(){
    $('.default').each(function(){
      var defaultVal = $(this).attr('title');
      if ($(this).val() == defaultVal){
        $(this).val('');
      }
    });
  });
});
</pre>
<p><a href="http://www.designchemical.com/lab/jquery/demo/jquery_form_input_default_text.htm" class="demo">View Default Text Demo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/add-default-text-to-form-fields-using-jquery/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Disable Form Input Autocomplete Using jQuery</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/disable-form-input-autocomplete-using-jquery/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/disable-form-input-autocomplete-using-jquery/#comments</comments>
		<pubDate>Wed, 03 Nov 2010 14:36:23 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=958</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/disable-form-input-autocomplete-using-jquery/"><img align="left" hspace="5" width="120" height="120" src="http://www.designchemical.com/blog/wp-content/uploads/2010/05/thumb_jquery_code.png" class="alignleft tfe wp-post-image" alt="thumb_jquery_code" title="thumb_jquery_code" /></a><p>Earlier I came across an interesting problem caused by a text input field&#8217;s autocomplete. Sometimes it is useful to be able to disable this feature in a users browser &#8211; e.g. for completing forms with sensitive information such as credit card numbers but using the attribute autocomplete=&#8221;off&#8221; on the input field would technically cause issues with validation.</p>
<p>One way to &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/disable-form-input-autocomplete-using-jquery/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>Earlier I came across an interesting problem caused by a text input field&#8217;s autocomplete. Sometimes it is useful to be able to disable this feature in a users browser &#8211; e.g. for completing forms with sensitive information such as credit card numbers but using the attribute autocomplete=&#8221;off&#8221; on the input field would technically cause issues with validation.</p>
<p>One way to get around this problem is to use jQuery to add the attribute. To do this we give the relevant input field the class &#8220;autoDisable&#8221;:</p>
<h3>The HTML</h3>
<pre class="brush: xml; title: ; notranslate">
&lt;input name=&quot;name&quot; type=&quot;text&quot; class=&quot;autoDisable&quot; value=&quot;&quot; /&gt;
</pre>
<h3>The jQuery</h3>
<pre class="brush: jscript; title: ; notranslate">
$('.autoDisable').attr('autocomplete','off');
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/disable-form-input-autocomplete-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Simple Vertical Accordion Menu with Cookies</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/jquery-simple-vertical-accordion-menu-with-cookies/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/jquery-simple-vertical-accordion-menu-with-cookies/#comments</comments>
		<pubDate>Fri, 24 Sep 2010 20:14:21 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Design Tips]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[accordion]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vertical]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=919</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/jquery-simple-vertical-accordion-menu-with-cookies/"><img align="left" hspace="5" width="120" height="120" src="http://www.designchemical.com/blog/wp-content/uploads/2010/05/thumb_jquery_code.png" class="alignleft tfe wp-post-image" alt="thumb_jquery_code" title="thumb_jquery_code" /></a><p>Using the jQuery code from one of our previous tutorials on creating a simple vertical navigation menu we can add the very useful jQuery cookie plugin to create a more advanced navigation menu that remembers your visitors last location.</p>
The HTML, jQuery and CSS
<p>To speed up the tutorial we will assume that you have already followed the initial postings &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/jquery-simple-vertical-accordion-menu-with-cookies/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>Using the jQuery code from one of our previous tutorials on <a href="http://www.designchemical.com/blog/index.php/jquery/jquery-simple-vertical-accordion-menu/">creating a simple vertical navigation menu</a> we can add the very useful <a href="http://stilbuero.de/jquery/cookie">jQuery cookie plugin</a> to create a more advanced navigation menu that remembers your visitors last location.</p>
<h3>The HTML, jQuery and CSS</h3>
<p>To speed up the tutorial we will assume that you have already followed the initial postings and therefore understand how to create the basic HTML/CSS structure for a vertical accordion menu and that you have the preliminary jQuery in place.</p>
<h3>Using jQuery Cookies</h3>
<p>What jQuery cookies allows us to do is very easily create/modify/store a cookie on the visitors computer that will hold the position of the last menu item visited. When they next visit the site we can therefore use this value to automatically open the relevent menu section.</p>
<h3>Creating a jQuery Cookie</h3>
<p>To create a cookie we simply declare the cookie name, followed by the value. For our accordion menu we will therefore create a cookie named &#8220;nav-item&#8221; and its value will be the index value of the last anchor tag clicked. So to create this we use:</p>
<pre class="brush: jscript; title: ; notranslate">
$('#nav &gt; li &gt; a').click(function(){
      var navIndex = $('#nav &gt; li &gt; a').index(this);
	  $.cookie(&quot;nav-item&quot;, navIndex);
	  $('#nav li ul').slideUp();
	   if ($(this).next().is(&quot;:visible&quot;)){
		   $(this).next().slideUp();
	   } else {
	   $(this).next().slideToggle();
	   }
	   $('#nav li a').removeClass('active');
	   $(this).addClass('active');
  });
</pre>
<p>In the above code &#8211; line 2 gets the index value and line 3 sets the cookie.</p>
<h3>Using the Cookie Value</h3>
<p>Now that we have a cookie on their computer we need to add the jQuery code that will check the visitors browser when the page loads, retrieve the cookie if it exists and use this to open the appropriate menu section:</p>
<pre class="brush: jscript; title: ; notranslate">
var checkCookie = $.cookie(&quot;nav-item&quot;);
  if (checkCookie != &quot;&quot;) {
	$('#nav &gt; li &gt; a:eq('+checkCookie+')').next().show();
  }
</pre>
<p>That is basically all that is required. Put it all together and the complete code &#8230;</p>
<h3>The Complete jQuery</h3>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function () {
  var checkCookie = $.cookie(&quot;nav-item&quot;);
  if (checkCookie != &quot;&quot;) {
	$('#nav &gt; li &gt; a:eq('+checkCookie+')').next().show();
  }
  $('#nav &gt; li &gt; a').click(function(){
      var navIndex = $('#nav &gt; li &gt; a').index(this);
	  $.cookie(&quot;nav-item&quot;, navIndex);
	  $('#nav li ul').slideUp();
	   if ($(this).next().is(&quot;:visible&quot;)){
		   $(this).next().slideUp();
	   } else {
	   $(this).next().slideToggle();
	   }
	   $('#nav li a').removeClass('active');
	   $(this).addClass('active');
  });
});
</pre>
<p><a href="http://www.designchemical.com/lab/jquery/demo/jquery_vertical_accordion_menu_using_cookies.htm" class="demo">Check out the online demo</a></p>
<h4 class="clear">Update 5th Mar 2011:</h4>
<p>We have now also released the <a href="/lab/jquery-vertical-accordion-menu-plugin/getting-started/">jQuery Vertical Accordion Menu Plugin</a>, which makes it easy to create accordion menus from any nested HTML lists. The plugin has several features including use of cookies and ability to select either hover or click to activate the menu.</p>
<p>Check out the project pages for more information and <a href="/lab/jquery-vertical-accordion-menu-plugin/examples/">examples</a> or go straight to the <a href="/lab/jquery-vertical-accordion-menu-plugin/download/">download page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/jquery-simple-vertical-accordion-menu-with-cookies/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>jQuery Simple Horizontal Accordion</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/jquery-simple-horizontal-accordion/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/jquery-simple-horizontal-accordion/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 08:17:31 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[accordion]]></category>
		<category><![CDATA[horizontal]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=874</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/jquery-simple-horizontal-accordion/"><img align="left" hspace="5" width="120" height="120" src="http://www.designchemical.com/blog/wp-content/uploads/2010/05/thumb_jquery_code.png" class="alignleft tfe wp-post-image" alt="thumb_jquery_code" title="thumb_jquery_code" /></a><p class="text-center"><img src="/media/images/jquery_horizontal_accordion.png" alt="" class="img-border" /></p>
<p>After our tutorial last month showing how to create a vertical accordion menu using jQuery we have had a couple of requests asking how to make a horizontal accordion.</p>
<p>So we have decided to provide the following post, which shows very easily how to use the power of jQuery to create a rather nice horizontal accordion effect.</p>
<strong>1.</strong><p> &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/jquery-simple-horizontal-accordion/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p class="text-center"><img src="/media/images/jquery_horizontal_accordion.png" alt="" class="img-border" /></p>
<p>After our tutorial last month showing how to <a href="/blog/index.php/jquery/jquery-simple-vertical-accordion-menu/">create a vertical accordion menu using jQuery</a> we have had a couple of requests asking how to make a horizontal accordion.</p>
<p>So we have decided to provide the following post, which shows very easily how to use the power of jQuery to create a rather nice horizontal accordion effect.</p>
<h3 class="clear"><strong>1. The HTML</strong></h3>
<p>First we create an unordered HTML list with id=&#8221;accordion&#8221; and include some content in each of the li tags &#8211; since the accordion is horizontal we have decided to use images to create the section labels:</p>
<pre class="brush: php; title: ; notranslate">
&lt;ul id=&quot;accordion&quot;&gt;
      &lt;li&gt;
        &lt;img src=&quot;images/section_1.png&quot; /&gt;
        &lt;strong&gt;Section 1 Header&lt;/strong&gt;&lt;br/&gt;
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. In iaculis volutpat quam, non suscipit arcu accumsan at. Aliquam pellentesque.
      &lt;/li&gt;
      &lt;li&gt;
        &lt;img src=&quot;images/section_2.png&quot; /&gt;
        &lt;strong&gt;Section 2 Header&lt;/strong&gt;&lt;br/&gt;
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. In iaculis volutpat quam, non suscipit arcu accumsan at. Aliquam pellentesque.
      &lt;/li&gt;
      &lt;li&gt;
        &lt;img src=&quot;images/section_3.png&quot; /&gt;
        &lt;strong&gt;Section 3 Header&lt;/strong&gt;&lt;br/&gt;
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. In iaculis volutpat quam, non suscipit arcu accumsan at. Aliquam pellentesque.
      &lt;/li&gt;
      &lt;li&gt;
        &lt;img src=&quot;images/section_4.png&quot; /&gt;
        &lt;strong&gt;Section 4 Header&lt;/strong&gt;&lt;br/&gt;
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. In iaculis volutpat quam, non suscipit arcu accumsan at. Aliquam pellentesque.
    &lt;/li&gt;
  &lt;/ul&gt;
</pre>
<div class="banner-horizontal">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-7740611438413740";
/* Banner Mid Post */
google_ad_slot = "8625321051";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<h3><strong>2. Style The Accordion</strong></h3>
<p>Next we add a few CSS rules, which will help style the accordion and its content:</p>
<pre class="brush: plain; title: ; notranslate">
#accordion {
list-style: none;
margin: 30px 0;
padding: 0;
height: 200px;
overflow: hidden;
background: #7d8d96;}

#accordion li {
float: left;
border-left:
display: block;
height: 170px;
width: 50px;
padding: 15px 0;
overflow: hidden;
color: #fff;
text-decoration: none;
font-size: 16px;
line-height: 1.5em;
border-left: 1px solid #fff;}

#accordion li img {
border: none;
border-right: 1px solid #fff;
float: left;
margin: -15px 15px 0 0;
}

#accordion li.active {
width: 450px;
}
</pre>
<p>The main items to take note of here are the widths of the li elements, which need to be the same as the min-width setting in our jQuery below and the width of the &#8220;active&#8221; tag, which should equal the max-width of the accordion section.</p>
<p>The &#8220;#accordion li.active&#8221; is also required to ensure that the default section is open when the page loads.</p>
<p>The rest is mainly styling of the background, text and positioning of the section header images.</p>
<h3><strong>3. The jQuery Code</strong></h3>
<p>Finally the jQuery to create the horizontal accordion effect &#8211; in this example we have used the &#8220;hover&#8221; event to trigger the animation:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function(){

    activeItem = $(&quot;#accordion li:first&quot;);
    $(activeItem).addClass('active');

	$(&quot;#accordion li&quot;).hover(function(){
		$(activeItem).animate({width: &quot;50px&quot;}, {duration:300, queue:false});
		$(this).animate({width: &quot;450px&quot;}, {duration:300, queue:false});
		activeItem = this;
	});

});
</pre>
<p>You can change which is the default open section upon page load by changing the &#8220;activeItem&#8221; variable &#8211; in our example we have used &#8220;#accordion li:first&#8221; to select the first list item.</p>
<p>Other options that can be changed include the min-width (in this case 50px) and the max-width, which we have set to 445px &#8211; the values in these lines must match the values given in the CSS rules above.</p>
<p>The duration setting controls the time in milliseconds for the accordion to animate from minimum to maximum width &#8211; again these can be set according to your preference.</p>
<p>The queue:false is required to stop the accordion capturing every hover event and continuing to animate after the mouse has left the hover area.</p>
<p><a href="/lab/jquery/demo/jquery_simple_horizontal_accordion.htm" class="demo">View the jQuery horizontal accordion demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/jquery-simple-horizontal-accordion/feed/</wfw:commentRss>
		<slash:comments>49</slash:comments>
		</item>
		<item>
		<title>jQuery Image Swap Using Click</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/jquery-image-swap-using-click/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/jquery-image-swap-using-click/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 09:56:11 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[images]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=834</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/jquery-image-swap-using-click/"><img align="left" hspace="5" width="120" height="120" src="http://www.designchemical.com/blog/wp-content/uploads/2010/05/thumb_jquery_code.png" class="alignleft tfe wp-post-image" alt="thumb_jquery_code" title="thumb_jquery_code" /></a><p>In a previous post we showed a simple piece of jQuery code, which allows you to add the ability to swap images on hover to your website. Since then we have had several requests asking how to add a similar effect using &#8220;click&#8221; instead.</p>
The Image
<p>Use the same naming system for the 2 images as in our previous post &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/jquery-image-swap-using-click/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>In a previous post we showed a simple piece of jQuery code, which allows you to add the ability to <a href="/blog/index.php/jquery/quick-and-easy-jquery-image-swap/">swap images on hover</a> to your website. Since then we have had several requests asking how to add a similar effect using &#8220;click&#8221; instead.</p>
<h3>The Image</h3>
<p>Use the same naming system for the 2 images as in our previous post &#8211; i.e. normal state called xxxxxx_off.jpg and the clicked state xxxxxx_on.jpg and add the class &#8220;img-swap&#8221; to the image tag in your HTML:</p>
<pre class="brush: plain; title: ; notranslate">
&lt;img src=&quot;xxxxxx_off.jpg&quot; class=&quot;img-swap&quot; /&gt;
</pre>
<h3>jQuery Code</h3>
<p>With just a few lines of jQuery you can now add the image swap function on click to any images in your web pages:</p>
<pre class="brush: jscript; title: ; notranslate">
$(function(){
  $(&quot;.img-swap&quot;).live('click', function() {
    if ($(this).attr(&quot;class&quot;) == &quot;img-swap&quot;) {
      this.src = this.src.replace(&quot;_off&quot;,&quot;_on&quot;);
    } else {
      this.src = this.src.replace(&quot;_on&quot;,&quot;_off&quot;);
    }
    $(this).toggleClass(&quot;on&quot;);
  });
});
</pre>
<p><a href="http://www.designchemical.com/lab/jquery/demo/jquery_image_swap_click.htm" class="demo">See the demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/jquery-image-swap-using-click/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>jQuery Simple Vertical Accordion Menu</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/jquery-simple-vertical-accordion-menu/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/jquery-simple-vertical-accordion-menu/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 02:40:50 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[accordion]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vertical]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=827</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/jquery-simple-vertical-accordion-menu/"><img align="left" hspace="5" width="120" height="120" src="http://www.designchemical.com/blog/wp-content/uploads/2010/05/thumb_jquery_code.png" class="alignleft tfe wp-post-image" alt="thumb_jquery_code" title="thumb_jquery_code" /></a><p>Today&#8217;s jQuery tutorial is a perfect example of how easy it is to add a slick vertical accordion style menu to your website with just a few lines of jQuery code!</p>
The HTML
<p>First we create a nested unordered list, which will include all of our links. Give the first ul tag a unique id &#8211; we use #nav:</p>
Style<p> &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/jquery-simple-vertical-accordion-menu/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s jQuery tutorial is a perfect example of how easy it is to add a slick vertical accordion style menu to your website with just a few lines of jQuery code!</p>
<h3>The HTML</h3>
<p>First we create a nested unordered list, which will include all of our links. Give the first ul tag a unique id &#8211; we use #nav:</p>
<pre class="brush: plain; title: ; notranslate">
&lt;ul id=&quot;nav&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Item 1&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Sub-Item 1 a&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Sub-Item 1 b&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Sub-Item 1 c&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Item 2&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Sub-Item 2 a&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Sub-Item 2 b&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Item 3&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Sub-Item 3 a&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Sub-Item 3 b&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Sub-Item 3 c&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Sub-Item 3 d&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Item 4&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Sub-Item 4 a&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Sub-Item 4 b&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Sub-Item 4 c&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</pre>
<h3>Style The Menu With CSS</h3>
<p>For this tutorial we add a little styling to the menu and use CSS to hide the sub-menus using &#8220;display: none;&#8221;:</p>
<pre class="brush: plain; title: ; notranslate">
#nav {float: left; width: 280px;  border-top: 1px solid #999; border-right: 1px solid #999; border-left: 1px solid #999;}
#nav li a {display: block; padding: 10px 15px; background: #ccc; border-top: 1px solid #eee; border-bottom: 1px solid #999; text-decoration: none; color: #000;}
#nav li a:hover, #nav li a.active {background: #999; color: #fff;}
#nav li ul {display: none;}
#nav li ul li a {padding: 10px 25px; background: #ececec; border-bottom: 1px dotted #ccc;}
</pre>
<h3>The jQuery Code</h3>
<p>To create the accordion effect the code is extremely simple:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function () {
  $('#nav &gt; li &gt; a').click(function(){
    if ($(this).attr('class') != 'active'){
      $('#nav li ul').slideUp();
      $(this).next().slideToggle();
      $('#nav li a').removeClass('active');
      $(this).addClass('active');
    }
  });
});
</pre>
<p>First we use the child selector &#8220;>&#8221; to ensure that only the parent links activate the accordion menu &#8211; otherwise you would end up closing the menu each time a sub-link is clicked.
<p>We add a new class to the active item &#8211; this allows us to not only style the open accordion menu but also identify if a sub-menu is open when a link is clicked. The above jQuery code will only work on closed menu items.</p>
<p><a href="http://www.designchemical.com/lab/jquery/demo/jquery_simple_accordion_menu.htm" class="demo">View the jQuery vertical accordion menu demo</a>.</p>
<h4 class="clear">Update 5th Mar 2011:</h4>
<p>We have now also released the <a href="/lab/jquery-vertical-accordion-menu-plugin/getting-started/">jQuery Vertical Accordion Menu Plugin</a>, which makes it easy to create accordion menus from any nested HTML lists. The plugin has several features including use of cookies and ability to select either hover or click to activate the menu.</p>
<p>Check out the project pages for more information and <a href="/lab/jquery-vertical-accordion-menu-plugin/examples/">examples</a> or go straight to the <a href="/lab/jquery-vertical-accordion-menu-plugin/download/">download page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/jquery-simple-vertical-accordion-menu/feed/</wfw:commentRss>
		<slash:comments>127</slash:comments>
		</item>
		<item>
		<title>Change Order of Multiple Select Lists Using jQuery</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/change-order-multiple-select-lists-using-jquery/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/change-order-multiple-select-lists-using-jquery/#comments</comments>
		<pubDate>Fri, 21 May 2010 09:36:27 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=448</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/change-order-multiple-select-lists-using-jquery/"><img align="left" hspace="5" width="120" height="120" src="http://www.designchemical.com/blog/wp-content/uploads/2010/05/thumb_jquery_code.png" class="alignleft tfe wp-post-image" alt="thumb_jquery_code" title="thumb_jquery_code" /></a><p>In my last post I went through the code required to create an add/remove select list using jQuery.</p>
<p>Today&#8217;s post is going to expand on the earlier tutorial and add up/down buttons, which will allow you to change the order of the option items in the select list.</p>
The HTML Code
<p>The HTML code for the select lists remains the &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/change-order-multiple-select-lists-using-jquery/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>In my last post I went through the code required to <a href="http://www.designchemical.com/blog/index.php/jquery/create-add-remove-select-lists-using-jquery/">create an add/remove select list using jQuery</a>.</p>
<p>Today&#8217;s post is going to expand on the earlier tutorial and add up/down buttons, which will allow you to change the order of the option items in the select list.</p>
<h3>The HTML Code</h3>
<p>The HTML code for the select lists remains the same as the earlier post, except with the addition of the &#8220;up&#8221; and &#8220;down&#8221; links:</p>
<pre class="brush: plain; title: ; notranslate">
&lt;form&gt;
  &lt;fieldset&gt;
    &lt;select name=&quot;selectfrom&quot; id=&quot;select-from&quot; multiple size=&quot;5&quot;&gt;
      &lt;option value=&quot;1&quot;&gt;Item 1&lt;/option&gt;
      &lt;option value=&quot;2&quot;&gt;Item 2&lt;/option&gt;
      &lt;option value=&quot;3&quot;&gt;Item 3&lt;/option&gt;
      &lt;option value=&quot;4&quot;&gt;Item 4&lt;/option&gt;
    &lt;/select&gt;
    &lt;a href=&quot;JavaScript:void(0);&quot; id=&quot;btn-add&quot;&gt;Add &amp;raquo;&lt;/a&gt;
    &lt;a href=&quot;JavaScript:void(0);&quot; id=&quot;btn-remove&quot;&gt;&amp;laquo; Remove&lt;/a&gt;
    &lt;select name=&quot;selectto&quot; id=&quot;select-to&quot; multiple size=&quot;5&quot;&gt;
      &lt;option value=&quot;5&quot;&gt;Item 5&lt;/option&gt;
      &lt;option value=&quot;6&quot;&gt;Item 6&lt;/option&gt;
      &lt;option value=&quot;7&quot;&gt;Item 7&lt;/option&gt;
    &lt;/select&gt;
    &lt;a href=&quot;JavaScript:void(0);&quot; id=&quot;btn-up&quot;&gt;Up&lt;/a&gt;
    &lt;a href=&quot;JavaScript:void(0);&quot; id=&quot;btn-down&quot;&gt;Down&lt;/a&gt;
  &lt;/fieldset&gt;
&lt;/form&gt;
</pre>
<h3>The jQuery Code</h3>
<p>Again, keeping the same code for the add/remove functions, we just need to add the additional jQuery to handle the up/down links:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function() {
    $('#btn-add').click(function(){
        $('#select-from option:selected').each( function() {
                $('#select-to').append(&quot;&lt;option value='&quot;+$(this).val()+&quot;'&gt;&quot;+$(this).text()+&quot;&lt;/option&gt;&quot;);
            $(this).remove();
        });
    });
    $('#btn-remove').click(function(){
        $('#select-to option:selected').each( function() {
            $('#select-from').append(&quot;&lt;option value='&quot;+$(this).val()+&quot;'&gt;&quot;+$(this).text()+&quot;&lt;/option&gt;&quot;);
            $(this).remove();
        });
    });
    $('#btn-up').bind('click', function() {
		$('#select-to option:selected').each( function() {
			var newPos = $('#select-to option').index(this) - 1;
			if (newPos &gt; -1) {
				$('#select-to option').eq(newPos).before(&quot;&lt;option value='&quot;+$(this).val()+&quot;' selected='selected'&gt;&quot;+$(this).text()+&quot;&lt;/option&gt;&quot;);
				$(this).remove();
			}
		});
	});
	$('#btn-down').bind('click', function() {
		var countOptions = $('#select-to option').size();
		$('#select-to option:selected').each( function() {
			var newPos = $('#select-to option').index(this) + 1;
			if (newPos &lt; countOptions) {
				$('#select-to option').eq(newPos).after(&quot;&lt;option value='&quot;+$(this).val()+&quot;' selected='selected'&gt;&quot;+$(this).text()+&quot;&lt;/option&gt;&quot;);
				$(this).remove();
			}
		});
	});
});
</pre>
<h3>1. The &#8220;Up&#8221; Link</h3>
<p>First we tackle the &#8220;up&#8221; link. Basically how we handle this is to retrieve the index value of each selected option, set the variable for the option items new position as &#8230; current index &#8211; 1, recreate the option HTML and insert it &#8220;before&#8221; the new index position. Finally &#8211; remove the old HTML from the list.</p>
<p>In order to make sure that we dont lose the option item off list list by trying to insert at an index position < 0 we do a quick check on the current position and only run the code if index > 0.</p>
<h3>2. The &#8220;Down&#8221; Link</h3>
<p>The down link is very similar except we set the new index postion to &#8220;current + 1&#8243; and insert the option HTML &#8220;after&#8221; this value.
<p>Once again we need to make sure that we dont lose the option item off the bottom of the list so we include an &#8220;if&#8221; statement, which checks the total number of items in the list and only runs the code if the new index position is less than the total items.</p>
<p>The above code also works for multiple selected items.</p>
<p><a href="/lab/jquery/demo/jquery_change_order_select_list.htm" class="demo">Check out the change order of select lists demo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/change-order-multiple-select-lists-using-jquery/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Create Add &amp; Remove Select Lists Using jQuery</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/create-add-remove-select-lists-using-jquery/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/create-add-remove-select-lists-using-jquery/#comments</comments>
		<pubDate>Wed, 19 May 2010 19:20:54 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=437</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/create-add-remove-select-lists-using-jquery/"><img align="left" hspace="5" width="120" height="120" src="http://www.designchemical.com/blog/wp-content/uploads/2010/05/thumb_jquery_code.png" class="alignleft tfe wp-post-image" alt="thumb_jquery_code" title="thumb_jquery_code" /></a><p>JQuery makes it very easy to select specific elements and their attributes in your web page HTML.</p>
<p>In the following tutorial I will show you how to use just a few lines of jQuery to create an add/remove select list for your website form.</p>
The Form HTML
<p>So here we have just 2 select lists with sample data &#8211; the &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/create-add-remove-select-lists-using-jquery/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>JQuery makes it very easy to select specific elements and their attributes in your web page HTML.</p>
<p>In the following tutorial I will show you how to use just a few lines of jQuery to create an add/remove select list for your website form.</p>
<h3>The Form HTML</h3>
<pre class="brush: plain; title: ; notranslate">
&lt;form&gt;
  &lt;fieldset&gt;

    &lt;select name=&quot;selectfrom&quot; id=&quot;select-from&quot; multiple size=&quot;5&quot;&gt;
      &lt;option value=&quot;1&quot;&gt;Item 1&lt;/option&gt;
      &lt;option value=&quot;2&quot;&gt;Item 2&lt;/option&gt;
      &lt;option value=&quot;3&quot;&gt;Item 3&lt;/option&gt;
      &lt;option value=&quot;4&quot;&gt;Item 4&lt;/option&gt;
    &lt;/select&gt;

    &lt;a href=&quot;JavaScript:void(0);&quot; id=&quot;btn-add&quot;&gt;Add &amp;raquo;&lt;/a&gt;
    &lt;a href=&quot;JavaScript:void(0);&quot; id=&quot;btn-remove&quot;&gt;&amp;laquo; Remove&lt;/a&gt;

    &lt;select name=&quot;selectto&quot; id=&quot;select-to&quot; multiple size=&quot;5&quot;&gt;
      &lt;option value=&quot;5&quot;&gt;Item 5&lt;/option&gt;
      &lt;option value=&quot;6&quot;&gt;Item 6&lt;/option&gt;
      &lt;option value=&quot;7&quot;&gt;Item 7&lt;/option&gt;
    &lt;/select&gt;

  &lt;/fieldset&gt;
&lt;/form&gt;
</pre>
<p>So here we have just 2 select lists with sample data &#8211; the top one listing the items &#8220;from&#8221;. There are also 2 anchor tags, which provide the &#8220;add&#8221; and &#8220;remove&#8221; links.</p>
<h3>The jQuery Code</h3>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function() {

    $('#btn-add').click(function(){
        $('#select-from option:selected').each( function() {
                $('#select-to').append(&quot;&lt;option value='&quot;+$(this).val()+&quot;'&gt;&quot;+$(this).text()+&quot;&lt;/option&gt;&quot;);
            $(this).remove();
        });
    });
    $('#btn-remove').click(function(){
        $('#select-to option:selected').each( function() {
            $('#select-from').append(&quot;&lt;option value='&quot;+$(this).val()+&quot;'&gt;&quot;+$(this).text()+&quot;&lt;/option&gt;&quot;);
            $(this).remove();
        });
    });

});
</pre>
<p>Basically what we do here is that when either of the &#8220;add&#8221; or &#8220;remove&#8221; links are clicked jQuery will get the values for all of the relevant options that are selected, recreate each option item HTML, insert it into the opposite select list and finally remove these items from the original list.</p>
<p><a href="/lab/jquery/demo/jquery_create_add_remove_select_list.htm" class="demo">Check out the jquery add &#038; remove select list demo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/create-add-remove-select-lists-using-jquery/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Simple Tabs with AJAX and jQuery</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/simple-tabs-with-ajax-and-jquery/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/simple-tabs-with-ajax-and-jquery/#comments</comments>
		<pubDate>Sun, 02 May 2010 18:15:46 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Design Tips]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=421</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/simple-tabs-with-ajax-and-jquery/"><img align="left" hspace="5" width="120" height="120" src="http://www.designchemical.com/blog/wp-content/uploads/2010/05/thumb_jquery_code.png" class="alignleft tfe wp-post-image" alt="thumb_jquery_code" title="thumb_jquery_code" /></a><p>One of the great things about jQuery is its complete suite of built in AJAX functions, which allow you to add quick and easy features to your website.</p>
<p>The example below came from a recent project to create an internal web application for a client, which utilised tab navigation, jQuery and AJAX to load data into the page without the &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/simple-tabs-with-ajax-and-jquery/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>One of the great things about jQuery is its complete suite of built in AJAX functions, which allow you to add quick and easy features to your website.</p>
<p>The example below came from a recent project to create an internal web application for a client, which utilised tab navigation, jQuery and AJAX to load data into the page without the need to refresh the web page.</p>
<h3>1. The HTML Code</h3>
<pre class="brush: plain; title: ; notranslate">

&lt;ul id=&quot;nav&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;page_1.html&quot;&gt;Page 1&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;page_2.html&quot;&gt;Page 2&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;page_3.html&quot;&gt;Page 3&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div id=&quot;ajax-content&quot;&gt;This is default text, which will be replaced&lt;/div&gt;
</pre>
<p>You can fill the &#8220;ajax-content&#8221; div with default text, which will be replaced when one of the tabs are clicked.</p>
<h3>2. The jQuery Code</h3>
<pre class="brush: jscript; title: ; notranslate">

$(document).ready(function() {
    $(&quot;#nav li a&quot;).click(function() {

        $(&quot;#ajax-content&quot;).empty().append(&quot;&lt;div id='loading'&gt;&lt;img src='images/loading.gif' alt='Loading' /&gt;&lt;/div&gt;&quot;);
        $(&quot;#nav li a&quot;).removeClass('current');
        $(this).addClass('current');

        $.ajax({ url: this.href, success: function(html) {
            $(&quot;#ajax-content&quot;).empty().append(html);
            }
	});
	return false;
    });
});
</pre>
<p>The above jQuery code will automatically use the URL written into each anchor tag as the source for the AJAX data.</p>
<p>So what is the above code doing?</p>
<ol>
<li>When a tab is clicked we first empty the contents of the ajax-content div and then load a loading graphic, whilst the content is being retrieved.</li>
<li>The jQuery then removes the &#8220;current&#8221; class from the tabs and adds the class to the newly clicked anchor tag allowing you to style the tabs to show which one is now active.</li>
<li>Once the data from the URL has been retrieved the loading image is removed and the content loaded into the &#8220;ajax-content&#8221; div.</li>
<li>Finally, the &#8220;return false&#8221; command is used to prevent the default action of the tabs browsing to the content pages.</li>
</ol>
<h3>3. Loading A Default Page</h3>
<p>If you wanted to use one of the external pages as your default content you can simply edit the code as below:</p>
<pre class="brush: jscript; title: ; notranslate">

$(document).ready(function() {
    $(&quot;#nav li a&quot;).click(function() {

        $(&quot;#ajax-content&quot;).empty().append(&quot;&lt;div id='loading'&gt;&lt;img src='images/loading.gif' alt='Loading' /&gt;&lt;/div&gt;&quot;);
        $(&quot;#nav li a&quot;).removeClass('current');
        $(this).addClass('current');

        $.ajax({ url: this.href, success: function(html) {
            $(&quot;#ajax-content&quot;).empty().append(html);
            }
	});
	return false;
    });

    $(&quot;#ajax-content&quot;).empty().append(&quot;&lt;div id='loading'&gt;&lt;img src='images/loading.gif' alt='Loading' /&gt;&lt;/div&gt;&quot;);
	$.ajax({ url: 'page_1.html', success: function(html) {
            $(&quot;#ajax-content&quot;).empty().append(html);
	}
    });
});
</pre>
<p>Substitute the URL for your required page in the code.</p>
<p>A very simple yet effective way to create a basic jQuery and AJAX application for your website</p>
<p><a href="/lab/jquery/demo/jquery_ajax_tabs_demo.htm" class="demo">Check out the demo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/simple-tabs-with-ajax-and-jquery/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How To Add Blog Posts To A WordPress Page</title>
		<link>http://www.designchemical.com/blog/index.php/wordpress-tips/how-to-add-blog-posts-to-a-wordpress-page/</link>
		<comments>http://www.designchemical.com/blog/index.php/wordpress-tips/how-to-add-blog-posts-to-a-wordpress-page/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 20:22:27 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[Wordpress Tips]]></category>
		<category><![CDATA[themes]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=389</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/wordpress-tips/how-to-add-blog-posts-to-a-wordpress-page/"><img align="left" hspace="5" width="150" height="150" src="http://www.designchemical.com/blog/wp-content/uploads/2010/05/thumb_wp_posts_page.png" class="alignleft tfe wp-post-image" alt="thumb_wp_posts_page" title="thumb_wp_posts_page" /></a><p>By default pages in WordPress websites will not display blog posts. However, there is a quick an easy way to edit the code of your theme page to handle this.</p>
1. WordPress Theme Page Code
<p>First create a new page for your theme. Then add the following code to the web page in the area where you normally display the &#8230; <a href="http://www.designchemical.com/blog/index.php/wordpress-tips/how-to-add-blog-posts-to-a-wordpress-page/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>By default pages in WordPress websites will not display blog posts. However, there is a quick an easy way to edit the code of your theme page to handle this.</p>
<h3>1. WordPress Theme Page Code</h3>
<p>First create a new page for your theme. Then add the following code to the web page in the area where you normally display the main content:</p>
<pre class="brush: plain; title: ; notranslate">
&lt;?php
global $more;
$more = 0;

  $post_per_page = 10; // -1 shows all posts
  $args=array('category_name' =&gt; 'Latest News', 'posts_per_page' =&gt; $post_per_page);
?&gt;

&lt;?php query_posts($args); ?&gt;
    &lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt;

        &lt;div class=&quot;post&quot; id=&quot;post-&lt;?php the_ID(); ?&gt;&quot;&gt;
            &lt;h3&gt;&lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot; title=&quot;&lt;?php the_title(); ?&gt;&quot;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h3&gt;
            &lt;?php the_content('read more ...'); ?&gt;
        &lt;/div&gt;

    &lt;?php endwhile; ?&gt;
&lt;?php endif; ?&gt;
</pre>
<p>The above code allows you to select posts from a specific categories and display the excerpts on the page. In this example we select our &#8220;Latest News&#8221; category &#8211; change the &#8216;category_name&#8217; => &#8216;Latest News&#8217; to suit your requirements.</p>
<p>You can also control the number of posts displayed by changing the &#8220;$post_per_page&#8221; parameter.</p>
<h3>2. How To Use In Your Page</h3>
<p>Very simply &#8211; upload your new template file to your themes folder, create a new page in your WordPress admin and assign the new template file to this page.</p>
<p>There you have it &#8211; a custom page on your WordPress website showing latest posts. To add more pages just repeat the process by creating a new theme page file and change category name parameter.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/wordpress-tips/how-to-add-blog-posts-to-a-wordpress-page/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Check Passwords Using jQuery</title>
		<link>http://www.designchemical.com/blog/index.php/jquery/check-passwords-using-jquery/</link>
		<comments>http://www.designchemical.com/blog/index.php/jquery/check-passwords-using-jquery/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 18:00:29 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Validation]]></category>
		<category><![CDATA[Web Design Tips]]></category>
		<category><![CDATA[Website Coding]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.designchemical.com/blog/?p=387</guid>
		<description><![CDATA[<a href="http://www.designchemical.com/blog/index.php/jquery/check-passwords-using-jquery/"><img align="left" hspace="5" width="120" height="120" src="http://www.designchemical.com/blog/wp-content/uploads/2010/05/thumb_jquery_code.png" class="alignleft tfe wp-post-image" alt="thumb_jquery_code" title="thumb_jquery_code" /></a><p>We have had several requests on how to use jQuery to check that passwords match in your website registration form when requesting visitors to re-enter their passwords.</p>
<p>This can easily be achieved by using similar code shown in our previous posts on Using jQuery to Validate Search Box Input and Email Validation Using jQuery.</p>
1. The Password Input Fields
2.<p> &#8230; <a href="http://www.designchemical.com/blog/index.php/jquery/check-passwords-using-jquery/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>We have had several requests on how to use jQuery to check that passwords match in your website registration form when requesting visitors to re-enter their passwords.</p>
<p>This can easily be achieved by using similar code shown in our previous posts on <a href="/blog/index.php/jquery/using-jquery-to-validate-search-box-input/">Using jQuery to Validate Search Box Input</a> and <a href="/blog/index.php/jquery/email-validation-using-jquery/">Email Validation Using jQuery</a>.</p>
<h3>1. The Password Input Fields</h3>
<pre class="brush: plain; title: ; notranslate">
&lt;form method=&quot;post&quot; name=&quot;form1&quot; id=&quot;form-password&quot; action=&quot;&quot;&gt;
  &lt;fieldset&gt;
    &lt;label&gt;Password:&lt;/label&gt;
    &lt;input type=&quot;password&quot; name=&quot;password&quot; id=&quot;password&quot; value=&quot;&quot; size=&quot;32&quot; /&gt;
    &lt;label&gt;Re-Enter Password:&lt;/label&gt;
    &lt;input type=&quot;password&quot; name=&quot;password-check&quot; id=&quot;password-check&quot; value=&quot;&quot; size=&quot;32&quot; /&gt;
    &lt;input type=&quot;submit&quot; value=&quot;Submit&quot; id=&quot;submit&quot;&gt;
  &lt;/fieldset&gt;
&lt;/form&gt;
</pre>
<h3>2. The jQuery Validation Code &#8211; Check That Both Passwords Match</h3>
<pre class="brush: jscript; title: ; notranslate">
jQuery(function(){
        $(&quot;#submit&quot;).click(function(){
        $(&quot;.error&quot;).hide();
        var hasError = false;
        var passwordVal = $(&quot;#password&quot;).val();
        var checkVal = $(&quot;#password-check&quot;).val();
        if (passwordVal == '') {
            $(&quot;#password&quot;).after('&lt;span class=&quot;error&quot;&gt;Please enter a password.&lt;/span&gt;');
            hasError = true;
        } else if (checkVal == '') {
            $(&quot;#password-check&quot;).after('&lt;span class=&quot;error&quot;&gt;Please re-enter your password.&lt;/span&gt;');
            hasError = true;
        } else if (passwordVal != checkVal ) {
            $(&quot;#password-check&quot;).after('&lt;span class=&quot;error&quot;&gt;Passwords do not match.&lt;/span&gt;');
            hasError = true;
        }
        if(hasError == true) {return false;}
    });
});
</pre>
<p>The above code will perform the following checks upon clicking the submit button:</p>
<ul>
<li>Check that a password has been entered and return an error message if the input field is empty.</li>
<li>Check that the &#8220;re-enter password&#8221; field contains text and return an error message if the input field is empty.</li>
<li>Finally &#8211; compare both password texts to check if they match</li>
</ul>
<p>If any of the validation checks return an error then the form submission on your website is stopped with the &#8220;return false&#8221; command.</p>
<p><a href="/lab/jquery/demo/check_passwords_using_jquery.htm" class="demo">Check out the demo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.designchemical.com/blog/index.php/jquery/check-passwords-using-jquery/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

