<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>JavaScript Tricks</title>
	<atom:link href="http://jstricks.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://jstricks.wordpress.com</link>
	<description>Helpful JavaScript ideas</description>
	<lastBuildDate>Tue, 02 Feb 2010 09:08:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='jstricks.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>JavaScript Tricks</title>
		<link>http://jstricks.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://jstricks.wordpress.com/osd.xml" title="JavaScript Tricks" />
	<atom:link rel='hub' href='http://jstricks.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Getting elements by class name</title>
		<link>http://jstricks.wordpress.com/2010/02/02/getting-elements-by-class-name/</link>
		<comments>http://jstricks.wordpress.com/2010/02/02/getting-elements-by-class-name/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 09:01:38 +0000</pubDate>
		<dc:creator>Paul Wilkins</dc:creator>
				<category><![CDATA[Class]]></category>
		<category><![CDATA[compatible]]></category>
		<category><![CDATA[cross-browser]]></category>
		<category><![CDATA[getElementsByClassName]]></category>

		<guid isPermaLink="false">http://jstricks.wordpress.com/?p=199</guid>
		<description><![CDATA[The topic of getting elements by their class name is one that has been covered by many people, but nothing seems to put together all of the information in such a way that it works across most of the web browsers out there. Within the past couple of years, modern web browsers have added their [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jstricks.wordpress.com&amp;blog=11309951&amp;post=199&amp;subd=jstricks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The topic of getting elements by their class name is one that has been covered by many people, but nothing seems to put together all of the information in such a way that it works across most of the web browsers out there.</p>
<p>Within the past couple of years, modern web browsers have added their own native <code>getElementsByTagName</code> that is incredibly fast, when compared with using a script. Other web browsers such as Internet Explorer do not have a native implementation, so still require a scripted solution for these other browsers. Here&#8217;s how to achieve that in a cross-browser manner.</p>
<p>Even though there are a wide variety of <code>getElementsByTagName</code> scripts that people have created, many of them only partially resolve the issle. Ultimately there are two major issues at hand:</p>
<ol>
<li>Detecting whether a browser already has a <code>getElementsByTagName</code> implementation</li>
<li>Limit the search by tag name, to assist slower web browsers</li>
</ol>
<p>The first issue is nicely resolved thanks to advice from <a href="http://www.sidroberts.co.uk/2008/06/06/getelementsbyclassname/">Sid Robert&#8217;s blog</a></p>
<p>Due to a number of compatibility issues with different web browsers, we need to assign the script to both <code>Object.prototype</code> and <code>document<span style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;">. As we don't want to overwrite the native implementation of <code>getElementsByTagName</code>, we'll use the || operator to attempt to assign the native implementation first so that if that fails, the anonymous function that follows it can be used instead.</span></code></p>
<pre><span style="color:#298a52;"><strong>Object</strong></span>.prototype.getElementsByClassName = <span style="color:#a52829;"><strong>document</strong></span>.getElementsByClassName =
    <span style="color:#a52829;"><strong>document</strong></span>.getElementsByClassName || <span style="color:#008a8c;">function</span> (searchClass, tag) <span style="color:#008a8c;">{</span></pre>
<p>John Resig has a <a href="http://ejohn.org/blog/getelementsbyclassname-speed-comparison/">getElementsByTagName Speed Comparison</a> that lists many of the popular <code>getElementsByTagName</code> functions. For this post I have chosen to use the one by Dustin Diaz, which has the fastest DOM implementation. This function is compatible back to IE6. In order to be compatible with IE5 we would need to use a different technique to obtain all of the tags, as using <code>'*'</code> with <code>getElementsByTagName</code> fails to work in IE5.</p>
<p>A few updates have been made to this function so that things like unspecified arguments are correctly detected, and that issues that might be picked up by <a href="http://jslint.com/">JSLint</a> are tidied up.</p>
<p>This is the cross-browser compatibility script for getElementsByClassName</p>
<pre><span style="color:#298a52;"><strong>Object</strong></span>.prototype.getElementsByClassName = <span style="color:#a52829;"><strong>document</strong></span>.getElementsByClassName =
    <span style="color:#a52829;"><strong>document</strong></span>.getElementsByClassName || <span style="color:#008a8c;">function</span> (searchClass, tag) <span style="color:#008a8c;">{</span>
    <span style="color:#a52829;"><strong>if</strong></span> (tag === <span style="color:#a52829;"><strong>undefined</strong></span>) <span style="color:#008a8c;">{</span>
        tag = <span style="color:#ff00ff;">'*'</span>;
    <span style="color:#008a8c;">}</span>
    <span style="color:#008a8c;">var</span> classElements = <span style="color:#008a8c;">[]</span>,
        els = <span style="color:#008a8c;">this</span>.getElementsByTagName(tag),
        elsLen = els.length,
        pattern = <span style="color:#a52829;"><strong>new</strong></span> <span style="color:#298a52;"><strong>RegExp</strong></span>(<span style="color:#ff00ff;">"(^|</span><span style="color:#6b59ce;">\\</span><span style="color:#ff00ff;">s)"</span> + searchClass + <span style="color:#ff00ff;">"(</span><span style="color:#6b59ce;">\\</span><span style="color:#ff00ff;">s|$)"</span>),
        i, j;
    <span style="color:#a52829;"><strong>for</strong></span> (i = 0, j = 0; i &lt; elsLen; i += 1) <span style="color:#008a8c;">{</span>
        <span style="color:#a52829;"><strong>if</strong></span> (pattern.test(els<span style="color:#008a8c;">[</span>i<span style="color:#008a8c;">]</span>.className)) <span style="color:#008a8c;">{</span>
            classElements<span style="color:#008a8c;">[</span>j<span style="color:#008a8c;">]</span> = els<span style="color:#008a8c;">[</span>i<span style="color:#008a8c;">]</span>;
            j += 1;
        <span style="color:#008a8c;">}</span>
    <span style="color:#008a8c;">}</span>
    <span style="color:#a52829;"><strong>return</strong></span> classElements;
<span style="color:#008a8c;">}</span>;</pre>
<p>With the above script running before other code that uses <code>el.getElementsByClassName</code>, you can now safely ensure that your code will run successfully on a wide range of web browsers.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jstricks.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jstricks.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jstricks.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jstricks.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jstricks.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jstricks.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jstricks.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jstricks.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jstricks.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jstricks.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jstricks.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jstricks.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jstricks.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jstricks.wordpress.com/199/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jstricks.wordpress.com&amp;blog=11309951&amp;post=199&amp;subd=jstricks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jstricks.wordpress.com/2010/02/02/getting-elements-by-class-name/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/aacfa176a8d73ca75b90b6375151765a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Paul</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting to the next element</title>
		<link>http://jstricks.wordpress.com/2010/01/15/getting-to-the-next-element/</link>
		<comments>http://jstricks.wordpress.com/2010/01/15/getting-to-the-next-element/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 10:02:19 +0000</pubDate>
		<dc:creator>Paul Wilkins</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[crossbrowser]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[nextSibling]]></category>
		<category><![CDATA[nodes]]></category>

		<guid isPermaLink="false">http://jstricks.wordpress.com/?p=195</guid>
		<description><![CDATA[Traversing the HTML DOM to get to the next element can be a tricky business. Take the following list as an example: &#60;ul&#62; &#60;li&#62;First item&#60;/li&#62; &#60;li&#62;Second item&#60;/li&#62; &#60;li&#62;Third item&#60;/li&#62; &#60;/ul&#62; Internet Explorer considers that there are only three nodes within the UL tag (the LI elements), whereas virtually all other modern web browsers consider that there [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jstricks.wordpress.com&amp;blog=11309951&amp;post=195&amp;subd=jstricks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Traversing the HTML DOM to get to the next element can be a tricky business.</p>
<p>Take the following list as an example:</p>
<pre><span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>ul</strong></span><span style="color:#008a8c;">&gt;</span>
    <span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>li</strong></span><span style="color:#008a8c;">&gt;</span>First item<span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>li</strong></span><span style="color:#008a8c;">&gt;</span>
    <span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>li</strong></span><span style="color:#008a8c;">&gt;</span>Second item<span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>li</strong></span><span style="color:#008a8c;">&gt;</span>
    <span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>li</strong></span><span style="color:#008a8c;">&gt;</span>Third item<span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>li</strong></span><span style="color:#008a8c;">&gt;</span>
<span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>ul</strong></span><span style="color:#008a8c;">&gt;</span></pre>
<p>Internet Explorer considers that there are only three nodes within the UL tag (the LI elements), whereas virtually all other modern web browsers consider that there are seven nodes within the UL element.</p>
<p>Three of the nodes are the LI elements, and the other four are text nodes, the whitespace between the tags, which consists of spaces, tabs, and newlines.</p>
<p>Text elements can also easily be normal text though. Consider the following:</p>
<pre><span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>p</strong></span><span style="color:#008a8c;">&gt;</span>Some text with <span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>a</strong></span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>href</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"link.html"</span><span style="color:#008a8c;">&gt;</span><span style="color:#6b59ce;">a link</span><span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>a</strong></span><span style="color:#008a8c;">&gt;</span>.<span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>p</strong></span><span style="color:#008a8c;">&gt;</span></pre>
<p>This paragraph contains two text nodes and an A element, which itself contains a text node.</p>
<pre><span style="color:#008a8c;">#text "<span style="color:#000000;">Some text with <span style="color:#008a8c;">"
<span style="color:#000000;"><span style="color:#008a8c;">A
<span style="color:#000000;"><span style="color:#008a8c;">  #attr <span style="color:#298a52;"><strong>href</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"link.html"</span>
<span style="color:#000000;"><span style="color:#008a8c;">  #text "</span><span style="color:#000000;">a link</span><span style="color:#008a8c;">"</span></span></span></span></span></span></span></span></span>
<span style="color:#008a8c;"><span style="color:#000000;"><span style="color:#008a8c;"><span style="color:#000000;"><span style="color:#008a8c;"><span style="color:#000000;"><span style="color:#008a8c;"><span style="color:#000000;"><span style="color:#008a8c;">#text "</span>.<span style="color:#008a8c;">"</span></span></span></span></span></span></span></span></span></pre>
<p>It is this difference between modern web browsers and Internet Explorer, that causes trouble when using direct node relationships such as the nextSibling property.</p>
<p>In many cases you can avoid this problem by using other techniques. With the unordered list for example, you can assign the UL element to a variable called <code>el</code> and use <code>document.getElementsByTagName('li')</code> to get all of the LI elements.</p>
<p>There can be times though when you need to step forward to the next element and avoid text nodes. As the <code>nodeType</code> of text elements is 1, and the <code>nodeType</code> of HTML tags is 3, we can use that as the basis for a useful tool.</p>
<pre><span style="color:#008a8c;">function</span> nextElement(el) <span style="color:#008a8c;">{</span>
    el = el.nextSibling;
    <span style="color:#a52829;"><strong>while</strong></span> (el &amp;&amp; el.nodeType === 1) <span style="color:#008a8c;">{</span>
        el = el.nextSibling;
    <span style="color:#008a8c;">}</span>
    <span style="color:#a52829;"><strong>return</strong></span> el;
<span style="color:#008a8c;">}</span></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jstricks.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jstricks.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jstricks.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jstricks.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jstricks.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jstricks.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jstricks.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jstricks.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jstricks.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jstricks.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jstricks.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jstricks.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jstricks.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jstricks.wordpress.com/195/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jstricks.wordpress.com&amp;blog=11309951&amp;post=195&amp;subd=jstricks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jstricks.wordpress.com/2010/01/15/getting-to-the-next-element/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/aacfa176a8d73ca75b90b6375151765a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Paul</media:title>
		</media:content>
	</item>
		<item>
		<title>Conclusion to sliders</title>
		<link>http://jstricks.wordpress.com/2010/01/13/conclusion-to-sliders/</link>
		<comments>http://jstricks.wordpress.com/2010/01/13/conclusion-to-sliders/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 06:08:28 +0000</pubDate>
		<dc:creator>Paul Wilkins</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery ui]]></category>
		<category><![CDATA[slider]]></category>

		<guid isPermaLink="false">http://jstricks.wordpress.com/?p=145</guid>
		<description><![CDATA[Now that scripting the slider regions is done, we have a finished and functional slider for our forms. This post is part of a series that guides you through creating robust sliders for your forms. Introduction to sliders Accessible slider alternative Basic requirements for sliders Connecting the slider to the form Scripting the slider regions Conclusion to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jstricks.wordpress.com&amp;blog=11309951&amp;post=145&amp;subd=jstricks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Now that <a href="http://jstricks.wordpress.com/2010/01/12/scripting-the-slider-regions/">scripting the slider regions</a> is done, we have a finished and functional slider for our forms.</p>
<p>This post is part of a series that guides you through creating robust sliders for your forms.</p>
<p><span id="more-145"></span></p>
<ol>
<li><a href="http://jstricks.wordpress.com/2010/01/11/introduction-to-sliders/">Introduction to sliders</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/11/accessible-slider-alternative/">Accessible slider alternative</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/11/basic-requirements-for-sliders/">Basic requirements for sliders</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/11/connecting-the-slider-to-the-form/">Connecting the slider to the form</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/12/scripting-the-slider-regions/">Scripting the slider regions</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/13/conclusion-to-sliders/">Conclusion to sliders</a> (this post)</li>
</ol>
<p>We have taken the scripting of some form questions from a basic yet functional beginning &#8230;</p>
<div id="attachment_66" class="wp-caption alignnone" style="width: 399px"><a href="http://jstricks.files.wordpress.com/2010/01/slider-form-without-javascript5.gif"><img class="size-full wp-image-66" title="slider-form-without-javascript" src="http://jstricks.files.wordpress.com/2010/01/slider-form-without-javascript5.gif?w=450" alt=""   /></a><p class="wp-caption-text">How the form looks without scripting</p></div>
<p>&#8230; and have made use of the <a href="http://">jQuery UI</a> library plus some scripting to create practical and easy to use sliders, that allow people to easily represent how they feel about things.</p>
<div id="attachment_117" class="wp-caption alignnone" style="width: 401px"><a href="http://jstricks.files.wordpress.com/2010/01/slider-form-in-use.gif"><img class="size-full wp-image-117" title="slider-form-in-use" src="http://jstricks.files.wordpress.com/2010/01/slider-form-in-use.gif?w=450" alt=""   /></a><p class="wp-caption-text">Slider form in use</p></div>
<p>Further progress from here might be to use a drop-down select to provide individualised region descriptions.</p>
<p>The slider bar is also capable of greater things than has been shown here. Instead of a smoothly sliding scale you can have fixed stopping points along the scale. You can also have two ends to the slider, so you can select a high point and a low point along the scale.</p>
<p>For a nice example of what can be done, Filament Group provide a plugin that turns the slider into a <a href="http://www.filamentgroup.com/lab/update_jquery_ui_slider_from_a_select_element_now_with_aria_support">wonderfully accessible slider</a>.</p>
<div id="attachment_190" class="wp-caption alignnone" style="width: 416px"><a href="http://jstricks.files.wordpress.com/2010/01/filament-group-slider.gif"><img class="size-full wp-image-190" title="filament-group-slider" src="http://jstricks.files.wordpress.com/2010/01/filament-group-slider.gif?w=450" alt=""   /></a><p class="wp-caption-text">Accessible slider from Filament Group</p></div>
<p>So have fun playing around with the slider from jQuery UI, I&#8217;ll be interested to hear about what results you get from it.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jstricks.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jstricks.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jstricks.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jstricks.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jstricks.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jstricks.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jstricks.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jstricks.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jstricks.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jstricks.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jstricks.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jstricks.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jstricks.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jstricks.wordpress.com/145/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jstricks.wordpress.com&amp;blog=11309951&amp;post=145&amp;subd=jstricks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jstricks.wordpress.com/2010/01/13/conclusion-to-sliders/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/aacfa176a8d73ca75b90b6375151765a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Paul</media:title>
		</media:content>

		<media:content url="http://jstricks.files.wordpress.com/2010/01/slider-form-without-javascript5.gif" medium="image">
			<media:title type="html">slider-form-without-javascript</media:title>
		</media:content>

		<media:content url="http://jstricks.files.wordpress.com/2010/01/slider-form-in-use.gif" medium="image">
			<media:title type="html">slider-form-in-use</media:title>
		</media:content>

		<media:content url="http://jstricks.files.wordpress.com/2010/01/filament-group-slider.gif" medium="image">
			<media:title type="html">filament-group-slider</media:title>
		</media:content>
	</item>
		<item>
		<title>Scripting the slider regions</title>
		<link>http://jstricks.wordpress.com/2010/01/12/scripting-the-slider-regions/</link>
		<comments>http://jstricks.wordpress.com/2010/01/12/scripting-the-slider-regions/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 04:36:40 +0000</pubDate>
		<dc:creator>Paul Wilkins</dc:creator>
				<category><![CDATA[Forms]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[jquery ui]]></category>
		<category><![CDATA[slider]]></category>

		<guid isPermaLink="false">http://jstricks.wordpress.com/?p=77</guid>
		<description><![CDATA[Now that we have connected the slider to the form, we can provide some added enhancement by showing in bold the appropriate region description underneath the slider. This post is part of a series that guides you through creating robust sliders for your forms. Introduction to sliders Accessible slider alternative Basic requirements for sliders Connecting the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jstricks.wordpress.com&amp;blog=11309951&amp;post=77&amp;subd=jstricks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Now that we have <a href="http://jstricks.wordpress.com/2010/01/11/connecting-the-slider-to-the-form/">connected the slider to the form</a>, we can provide some added enhancement by showing in bold the appropriate region description underneath the slider.</p>
<p>This post is part of a series that guides you through creating robust sliders for your forms.<span id="more-77"></span></p>
<ol>
<li><a href="http://jstricks.wordpress.com/2010/01/11/introduction-to-sliders/">Introduction to sliders</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/11/accessible-slider-alternative/">Accessible slider alternative</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/11/basic-requirements-for-sliders/">Basic requirements for sliders</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/11/connecting-the-slider-to-the-form/">Connecting the slider to the form</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/12/scripting-the-slider-regions/">Scripting the slider regions</a> (this post)</li>
<li><a href="http://jstricks.wordpress.com/2010/01/13/conclusion-to-sliders/">Conclusion to sliders</a></li>
</ol>
<p>To set the active slider region, we will walk through each region and set one of them to have a class name called <code>selected</code>. While we&#8217;re walking through each of them, we can handle situations where the region changes to a different description, by removing the <code>selected</code> class name from the regions beforehand.</p>
<p>To tell if a region is the right one or not, we can convert the slider value to a number for each of the regions, where we use <code>Math.floor</code> to round down the slider value after division.</p>
<pre><span style="color:#008a8c;">var</span> $ul = $(ui.handle).<span style="color:#a52829;"><span style="font-weight:bold;">parent</span></span>().next(<span style="color:#ff00ff;">'ul'</span>),
    $regions = $(<span style="color:#ff00ff;">'li'</span>, $ul),
    region = Math.floor(ui.value * $regions.length / 100);</pre>
<p>This works well with numbers from 0 to 99, but the slider ends at 100 so we also need to ensure that the <code>region</code> value doesn&#8217;t fall outside the number of regions.</p>
<pre><span style="color:#a52829;"><span style="font-weight:bold;">if</span></span> (region &gt; $regions.length) <span style="color:#008a8c;">{</span>
    region = $regions.length;
<span style="color:#008a8c;">}</span></pre>
<p>Even though can easily specify the min and max numbers for the slider, ending the slider at 100 provides the user with a more complete experience.</p>
<p>Now that we have the regions, and we know which one we want to be selected, we can walk through each region and the set the class name as is appropriate for each one.</p>
<pre>$regions.each(<span style="color:#008a8c;">function</span> (index) <span style="color:#008a8c;">{</span>
    $(<span style="color:#008a8c;">this</span>).removeClass(<span style="color:#ff00ff;">'selected'</span>);
    <span style="color:#a52829;"><span style="font-weight:bold;">if</span></span> (region === index) <span style="color:#008a8c;">{</span>
        $(<span style="color:#008a8c;">this</span>).addClass(<span style="color:#ff00ff;">'selected'</span>);
    <span style="color:#008a8c;">}</span>
<span style="color:#008a8c;">}</span>);</pre>
<p>The regions now change depending on where the slider is positioned.</p>
<div class="wp-caption alignnone" style="width: 401px"><a href="http://jstricks.files.wordpress.com/2010/01/slider-form-in-use.gif"><img class="size-full wp-image-117" title="slider-form-in-use" src="http://jstricks.files.wordpress.com/2010/01/slider-form-in-use.gif?w=450" alt=""   /></a><p class="wp-caption-text">Slider form in use</p></div>
<p>Next: Conclusion to sliders</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jstricks.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jstricks.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jstricks.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jstricks.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jstricks.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jstricks.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jstricks.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jstricks.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jstricks.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jstricks.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jstricks.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jstricks.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jstricks.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jstricks.wordpress.com/77/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jstricks.wordpress.com&amp;blog=11309951&amp;post=77&amp;subd=jstricks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jstricks.wordpress.com/2010/01/12/scripting-the-slider-regions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/aacfa176a8d73ca75b90b6375151765a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Paul</media:title>
		</media:content>

		<media:content url="http://jstricks.files.wordpress.com/2010/01/slider-form-in-use.gif" medium="image">
			<media:title type="html">slider-form-in-use</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating the sliders</title>
		<link>http://jstricks.wordpress.com/2010/01/11/creating-the-sliders/</link>
		<comments>http://jstricks.wordpress.com/2010/01/11/creating-the-sliders/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 03:57:49 +0000</pubDate>
		<dc:creator>Paul Wilkins</dc:creator>
				<category><![CDATA[Forms]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[jquery ui]]></category>
		<category><![CDATA[slider]]></category>

		<guid isPermaLink="false">http://jstricks.wordpress.com/?p=36</guid>
		<description><![CDATA[When creating our sliders, the changes that we want to make are: add an empty div to contain the slider add some region descriptions beneath the slider hide the input field This post is part of a series that guides you through creating robust sliders for your forms. Introduction to sliders Accessible slider alternative Basic requirements [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jstricks.wordpress.com&amp;blog=11309951&amp;post=36&amp;subd=jstricks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When creating our sliders, the changes that we want to make are:</p>
<ul>
<li>add an empty div to contain the slider</li>
<li>add some region descriptions beneath the slider</li>
<li>hide the input field</li>
</ul>
<p>This post is part of a series that guides you through creating robust sliders for your forms.<span id="more-36"></span></p>
<ol>
<li><a href="http://jstricks.wordpress.com/2010/01/11/introduction-to-sliders/">Introduction to sliders</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/11/accessible-slider-alternative/">Accessible slider alternative</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/11/basic-requirements-for-sliders/">Basic requirements for sliders</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/11/creating-the-sliders/">Creating the sliders</a> (this post)</li>
<li><a href="http://jstricks.wordpress.com/2010/01/12/scripting-the-slider-regions/">Scripting the slider regions</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/13/conclusion-to-sliders/">Conclusion to sliders</a></li>
</ol>
<p>After the paragraph, we need to add the div for the slider, as well as the list of regions.</p>
<pre>$(<span style="color:#ff00ff;">'p.slider'</span>).after(
    <span style="color:#ff00ff;">'&lt;div class="slider"&gt;&lt;/div&gt;'</span> +
    <span style="color:#ff00ff;">'&lt;ul class="slider"&gt;'</span> +
        <span style="color:#ff00ff;">'&lt;li&gt;I strongly disagree&lt;/li&gt;'</span> +
        <span style="color:#ff00ff;">'&lt;li&gt;I disagree&lt;/li&gt;'</span> +
        <span style="color:#ff00ff;">'&lt;li&gt;I am indifferent&lt;/li&gt;'</span> +
        <span style="color:#ff00ff;">'&lt;li&gt;I agree somewhat&lt;/li&gt;'</span> +
        <span style="color:#ff00ff;">'&lt;li&gt;I strongly agree&lt;/li&gt;'</span> +
    <span style="color:#ff00ff;">'&lt;ul&gt;'</span>
);</pre>
<p>This HTML code is being added from the script, instead of being hidden in the original HTML code, because this list is not useful on an unscripted page. Also, when there are multiple sliders on a page, repeated information such as this is best managed from just the one location.</p>
<p>The basic CSS for this list floats each region description to the left on the same line, and we can neatly <a href="http://www.quirksmode.org/css/clearing.html">clear the floats</a> with <code>overflow: hidden;</code> and <code>width: 100%</code> on the whole list, to ensure that the list box fully expands to include the floated items. Otherwise some spacing issues can occur.</p>
<pre><span style="color:#a52829;"><strong>ul</strong></span><span style="color:#6b59ce;">.</span>slider <span style="color:#008a8c;">{</span>
    <span style="color:#298a52;"><strong>margin-left</strong></span>: <span style="color:#ff00ff;">0</span>;
    <span style="color:#298a52;"><strong>padding-left</strong></span>: <span style="color:#ff00ff;">0</span>;
    <span style="color:#298a52;"><strong>overflow</strong></span>: <span style="color:#298a52;"><strong>hidden</strong></span>;
    <span style="color:#298a52;"><strong>width</strong></span>: <span style="color:#ff00ff;">100%</span>;
<span style="color:#008a8c;">}</span>
<span style="color:#a52829;"><strong>ul</strong></span><span style="color:#6b59ce;">.</span>slider <span style="color:#a52829;"><strong>li</strong></span> <span style="color:#008a8c;">{</span>
    <span style="color:#298a52;"><strong>margin-left</strong></span>: <span style="color:#ff00ff;">0</span>;
    <span style="color:#298a52;"><strong>padding-left</strong></span>: <span style="color:#ff00ff;">0</span>;
    <span style="color:#298a52;"><strong>list-style-type</strong></span>: <span style="color:#298a52;"><strong>none</strong></span>;
    <span style="color:#298a52;"><strong>float</strong></span>: <span style="color:#298a52;"><strong>left</strong></span>;
<span style="color:#008a8c;">}</span></pre>
<p>We can also help to make the regions look better, by making each of them 20% of the width, and coloring the unchosen list items in a light grey color.</p>
<pre><span style="color:#a52829;"><strong>ul</strong></span><span style="color:#6b59ce;">.</span>slider <span style="color:#a52829;"><strong>li</strong></span> <span style="color:#008a8c;">{</span>
    <span style="color:#298a52;"><strong>width</strong></span>: <span style="color:#ff00ff;">20%</span>;
<span style="color:#008a8c;">}</span>
<span style="color:#a52829;"><strong>ul</strong></span><span style="color:#6b59ce;">.</span>slider <span style="color:#a52829;"><strong>li</strong></span> <span style="color:#008a8c;">{</span>
    <span style="color:#298a52;"><strong>color</strong></span>: <span style="color:#ff00ff;">#ccc</span>;
<span style="color:#008a8c;">}</span>
<span style="color:#a52829;"><strong>ul</strong></span><span style="color:#6b59ce;">.</span>slider <span style="color:#a52829;"><strong>li</strong></span><span style="color:#6b59ce;">.</span>active <span style="color:#008a8c;">{</span>
    <span style="color:#298a52;"><strong>color</strong></span>: <span style="color:#ff00ff;">black</span>;
<span style="color:#008a8c;">}</span></pre>
<p>We can now hide the existing input field and activate the sliders:</p>
<pre>$(<span style="color:#ff00ff;">'p.slider input'</span>).hide();
$(<span style="color:#ff00ff;">'div.slider'</span>).slider();</pre>
<div id="attachment_23" class="wp-caption alignnone" style="width: 400px"><a href="http://jstricks.files.wordpress.com/2010/01/slider-form-ready-to-use.gif"><img class="size-full wp-image-23" title="slider-form-ready-to-use" src="http://jstricks.files.wordpress.com/2010/01/slider-form-ready-to-use.gif?w=450" alt=""   /></a><p class="wp-caption-text">Form sliders ready to use</p></div>
<p>Even though the sliders are now visible, we still need to:</p>
<ul>
<li>connect the slider to the form</li>
<li>update the number on the slider bar</li>
<li>update the form field value</li>
</ul>
<p>As we will be updating the slider whenever it moves, we want to use the <code>slide</code> event so that we can make some updates  while the slider is in motion.</p>
<p>Change the last line of the above code to the following:</p>
<pre>$(<span style="color:#ff00ff;">'div.slider'</span>).slider(<span style="color:#008a8c;">{</span>
    slide: <span style="color:#008a8c;">function</span> (<span style="color:#a52829;"><strong>event</strong></span>, ui) <span style="color:#008a8c;">{</span>

    <span style="color:#008a8c;">}</span>
<span style="color:#008a8c;">}</span>);</pre>
<p>When the slider is moved, we want to update the input field with the slider value. We can find the input field by starting from the slider handle and going up the DOM tree to the div element. From there we can move to the paragraph that comes before it. From the context of that paragraph we can get the input field, and set its value to that of the slider.</p>
<pre><span style="color:#008a8c;">var</span> $para = $(ui.handle).<span style="color:#a52829;"><strong>parent</strong></span>().prev();
$(<span style="color:#ff00ff;">'input'</span>, $para).val(ui.value);</pre>
<p>The dollar sign in front of the para variable helps to remind us that it is not a standard element, but is a jQuery object instead.</p>
<p>This is also a good time to provide some visual feedback on the slider itself, where we update the slider handle with the same value.</p>
<pre>$(ui.handle).text(ui.value);</pre>
<p>As there is going to be some other scripting in this same area later on, I&#8217;ll place these scripts inside their own function called <code>updateValue</code>, which helps to make the code easier to understand.</p>
<p>Add this code to the function in the slider for the slide event:</p>
<pre><span style="color:#008a8c;">function</span> updateValue (ui) <span style="color:#008a8c;">{</span>
    <span style="color:#008a8c;">var</span> $para = $(ui.handle).<span style="color:#a52829;"><strong>parent</strong></span>().prev();
    $(<span style="color:#ff00ff;">'input'</span>, $para).val(ui.value);
    $(ui.handle).text(ui.value);
<span style="color:#008a8c;">}</span>
updateValue(ui);</pre>
<p>We can now see on the slider that the number has an underline on it (which is a hang-over from being link element) and that the value is left aligned, which makes single-digit values look askew. With the addition of a few style declarations, we can tidy these things up.</p>
<pre><span style="color:#a52829;"><strong>div</strong></span><span style="color:#6b59ce;">.</span>slider <span style="color:#a52829;"><strong>a</strong></span> <span style="color:#008a8c;">{</span>
    <span style="color:#298a52;"><strong>text-align</strong></span>: <span style="color:#298a52;"><strong>center</strong></span>;
    <span style="color:#298a52;"><strong>text-decoration</strong></span>: <span style="color:#298a52;"><strong>none</strong></span>;
<span style="color:#008a8c;">}</span></pre>
<p>The slider can now be used with the form.</p>
<p>This is what the scripting code in <code>js/scripts.js</code> now looks like:</p>
<pre>$(<span style="color:#008a8c;">function</span> () <span style="color:#008a8c;">{</span>
    $(<span style="color:#ff00ff;">'p.slider input'</span>).hide();
    $(<span style="color:#ff00ff;">'p.slider'</span>).after(
        <span style="color:#ff00ff;">'&lt;div class="slider"&gt;&lt;/div&gt;'</span> +
        <span style="color:#ff00ff;">'&lt;ul class="slider"&gt;'</span> +
            <span style="color:#ff00ff;">'&lt;li&gt;I strongly disagree&lt;/li&gt;'</span> +
            <span style="color:#ff00ff;">'&lt;li&gt;I disagree&lt;/li&gt;'</span> +
            <span style="color:#ff00ff;">'&lt;li&gt;I am indifferent&lt;/li&gt;'</span> +
            <span style="color:#ff00ff;">'&lt;li&gt;I agree somewhat&lt;/li&gt;'</span> +
            <span style="color:#ff00ff;">'&lt;li&gt;I strongly agree&lt;/li&gt;'</span> +
        <span style="color:#ff00ff;">'&lt;/ul&gt;'</span>
    );
    $(<span style="color:#ff00ff;">'div.slider'</span>).slider(<span style="color:#008a8c;">{</span>
        slide: <span style="color:#008a8c;">function</span> (<span style="color:#a52829;"><strong>event</strong></span>, ui) <span style="color:#008a8c;">{</span>
            <span style="color:#008a8c;">function</span> updateValue (ui) <span style="color:#008a8c;">{</span>
                <span style="color:#008a8c;">var</span> $para = $(ui.handle).<span style="color:#a52829;"><strong>parent</strong></span>().prev();
                $(<span style="color:#ff00ff;">'input'</span>, $para).val(ui.value);
                $(ui.handle).text(ui.value);
            <span style="color:#008a8c;">}</span>
            updateValue(ui);
        <span style="color:#008a8c;">}</span>
    <span style="color:#008a8c;">}</span>);
<span style="color:#008a8c;">}</span>);</pre>
<p>Now that the slider is working, we can finish up by scripting the regions that are underneath the slider.</p>
<p>Next: <a href="http://jstricks.wordpress.com/2010/01/12/scripting-the-slider-regions/">Scripting the slider regions</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jstricks.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jstricks.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jstricks.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jstricks.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jstricks.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jstricks.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jstricks.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jstricks.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jstricks.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jstricks.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jstricks.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jstricks.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jstricks.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jstricks.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jstricks.wordpress.com&amp;blog=11309951&amp;post=36&amp;subd=jstricks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jstricks.wordpress.com/2010/01/11/creating-the-sliders/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/aacfa176a8d73ca75b90b6375151765a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Paul</media:title>
		</media:content>

		<media:content url="http://jstricks.files.wordpress.com/2010/01/slider-form-ready-to-use.gif" medium="image">
			<media:title type="html">slider-form-ready-to-use</media:title>
		</media:content>
	</item>
		<item>
		<title>Basic requirements for sliders</title>
		<link>http://jstricks.wordpress.com/2010/01/11/basic-requirements-for-sliders/</link>
		<comments>http://jstricks.wordpress.com/2010/01/11/basic-requirements-for-sliders/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 03:00:37 +0000</pubDate>
		<dc:creator>Paul Wilkins</dc:creator>
				<category><![CDATA[Forms]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[jquery ui]]></category>
		<category><![CDATA[slider]]></category>

		<guid isPermaLink="false">http://jstricks.wordpress.com/?p=34</guid>
		<description><![CDATA[When scripting is available,  we can update the form to provide sliders for our questions. Before that happens though, we need to add the jQuery UI library to the head of the page, which does much of the slider work for us. This post is part of a series that guides you through creating robust [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jstricks.wordpress.com&amp;blog=11309951&amp;post=34&amp;subd=jstricks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When scripting is available,  we can update the form to provide sliders for our questions. Before that happens though, we need to add the <a href="http://jqueryui.com/">jQuery UI</a> library to the head of the page, which does much of the slider work for us.</p>
<p>This post is part of a series that guides you through creating robust sliders for your forms.<span id="more-34"></span></p>
<ol>
<li><a href="http://jstricks.wordpress.com/2010/01/11/introduction-to-sliders/">Introduction to sliders</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/11/accessible-slider-alternative/">Accessible slider alternative</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/11/basic-requirements-for-sliders/">Basic requirements for sliders</a> (this post)</li>
<li><a href="http://jstricks.wordpress.com/2010/01/11/creating-the-slider/">Creating the sliders</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/12/scripting-the-slider-regions/">Scripting the slider regions</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/13/conclusion-to-sliders/">Conclusion to sliders</a></li>
</ol>
<p>To get started you will need to download a copy of <a href="http://jqueryui.com/">jQuery UI</a> to your computer. When you build your own download, you won&#8217;t need more than the Core and Slider components, but feel free to choose more of them if you want to explore further.</p>
<p>This example code uses just the stylesheet from the download, so copy the contents of the css folder from your download to the css folder of your slider form.</p>
<p>Add this code to the head of your web page and jQuery UI will be ready to be used.</p>
<pre><span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>link</strong></span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>type</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"text/css"</span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>rel</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"stylesheet"
<span style="color:#000000;"><span style="color:#008a8c;">    </span><span style="color:#298a52;"><strong>href</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"css/ui-lightness/jquery-ui-1.7.2.custom.css"</span><span style="color:#008a8c;">&gt;</span></span></span>
<span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>script</strong></span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>type</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"text/javascript"</span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>src</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"http://www.google.com/jsapi"</span><span style="color:#008a8c;">&gt;</span><span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>script</strong></span><span style="color:#008a8c;">&gt;</span>
<span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>script</strong></span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>type</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"text/javascript"</span><span style="color:#008a8c;">&gt;</span>
<span style="color:#6b59ce;">google.load</span>(<span style="color:#ff00ff;">"jquery"</span><span style="color:#6b59ce;">, </span><span style="color:#ff00ff;">"1.3.2"</span>)<span style="color:#6b59ce;">;</span>
<span style="color:#6b59ce;">google.load</span>(<span style="color:#ff00ff;">"jqueryui"</span><span style="color:#6b59ce;">, </span><span style="color:#ff00ff;">"1.7.2"</span>)<span style="color:#6b59ce;">;</span>
<span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>script</strong></span><span style="color:#008a8c;">&gt;</span></pre>
<p>We have chosen to get the script files from google, which has two main benefits:</p>
<ul>
<li>The library files for <a href="http://jquery.com/">jQuery</a> and <a href="http://jqueryui.com/">jQuery UI</a> are accessed in parallel with the rest of your  web page</li>
<li>The files are more likely to have already been cached on a persons computer from other web sites, so they don&#8217;t need to be downloaded a second time</li>
</ul>
<p>We can now go ahead and modify the HTML code from the <a href="http://jstricks.wordpress.com/2010/01/11/unscripted-form-for-sliders/">Unscripted Form for Sliders</a> post. The only change that we make to the form is to add a class name to each form paragraph.</p>
<p>Add a class name of <code>slider</code> to each paragraph that we intend to use for the slider, so that our script will know what we want to use for the sliders. For example, the first paragraph now looks like this:</p>
<pre><span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>p</strong></span> <span style="color:#298a52;"><strong>class</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"slider"</span><span style="color:#008a8c;">&gt;&lt;</span><span style="color:#a52829;"><strong>label</strong></span><span style="color:#008a8c;">&gt;</span>
    Clowns are scary creatures
    <span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>input</strong></span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>type</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"text"</span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>name</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"clowns"</span><span style="color:#008a8c;">&gt;</span>
<span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>label</strong></span><span style="color:#008a8c;">&gt;&lt;/</span><span style="color:#a52829;"><strong>p</strong></span><span style="color:#008a8c;">&gt;</span></pre>
<p>Now we can target the paragraphs denoted as <code>slider</code> and use scripting to make further changes to the form.</p>
<p>We will be using jQuery for our scripting, so we will place our script code in a scripting file called <code>js/script.js</code><br />
In the head of the page, add this after the script that loads jQuery UI</p>
<pre><span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>script</strong></span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>type</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"text/javascript"</span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>src</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"js/script.js"</span><span style="color:#008a8c;">&gt;</span><span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>script</strong></span><span style="color:#008a8c;">&gt;</span></pre>
<p>and place this code in <code>js/script.js</code></p>
<pre>$(<span style="color:#008a8c;">function</span> () <span style="color:#008a8c;">{</span>

<span style="color:#008a8c;">}</span>);</pre>
<p>We will be placing our jQuery code inside the above function.</p>
<p>Things are now ready for us to go ahead and create our sliders.<br />
Next: <a href="http://jstricks.wordpress.com/2010/01/11/creating-the-sliders/">Creating the sliders</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jstricks.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jstricks.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jstricks.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jstricks.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jstricks.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jstricks.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jstricks.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jstricks.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jstricks.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jstricks.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jstricks.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jstricks.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jstricks.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jstricks.wordpress.com/34/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jstricks.wordpress.com&amp;blog=11309951&amp;post=34&amp;subd=jstricks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jstricks.wordpress.com/2010/01/11/basic-requirements-for-sliders/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/aacfa176a8d73ca75b90b6375151765a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Paul</media:title>
		</media:content>
	</item>
		<item>
		<title>Accessible slider alternative</title>
		<link>http://jstricks.wordpress.com/2010/01/11/accessible-slider-alternative/</link>
		<comments>http://jstricks.wordpress.com/2010/01/11/accessible-slider-alternative/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 02:56:51 +0000</pubDate>
		<dc:creator>Paul Wilkins</dc:creator>
				<category><![CDATA[Forms]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[accessible]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[jquery ui]]></category>
		<category><![CDATA[slider]]></category>

		<guid isPermaLink="false">http://jstricks.wordpress.com/?p=32</guid>
		<description><![CDATA[The Introduction to sliders post explained that before we proceed on to using scriptable sliders, we need to ensure that an accessible version is available for when scripting is not used. This post is part of a series that guides you through creating robust sliders for your forms. Introduction to sliders Accessible slider alternative (this post) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jstricks.wordpress.com&amp;blog=11309951&amp;post=32&amp;subd=jstricks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://jstricks.wordpress.com/2010/01/11/introduction-to-sliders/">Introduction to sliders</a> post explained that before we proceed on to using scriptable sliders, we need to ensure that an accessible version is available for when scripting is not used.</p>
<p>This post is part of a series that guides you through creating robust sliders for your forms.<span id="more-32"></span></p>
<ol>
<li><a href="http://jstricks.wordpress.com/2010/01/11/introduction-to-sliders/">Introduction to sliders</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/11/accessible-slider-alternative/">Accessible slider alternative</a> (this post)</li>
<li><a href="http://jstricks.wordpress.com/2010/01/11/basic-requirements-for-sliders/">Basic requirements for sliders</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/11/connecting-the-slider-to-the-form/">Connecting the slider to the form</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/12/scripting-the-slider-regions/">Scripting the slider regions</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/13/conclusion-to-sliders/">Conclusion to sliders</a></li>
</ol>
<p>Before we get on with scripting, let&#8217;s create the base form with which we will use sliders.</p>
<p>This is the HTML code for the standard form that we will use for when scripting is not available to create the sliders.</p>
<pre><span style="color:#0000ff;">&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"</span>
<span style="color:#0000ff;"> "http://www.w3.org/TR/html4/strict.dtd"&gt;</span>
<span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>html</strong></span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>lang</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"en"</span><span style="color:#008a8c;">&gt;</span>
<span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>head</strong></span><span style="color:#008a8c;">&gt;</span>
<span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>meta</strong></span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>http-equiv</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"Content-Type"</span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>content</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"text/html; charset=utf-8"</span><span style="color:#008a8c;">&gt;</span>
<span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>title</strong></span><span style="color:#008a8c;">&gt;</span><span style="color:#ff00ff;"><strong>Sample sliders</strong></span><span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>title</strong></span><span style="color:#008a8c;">&gt;</span>
<span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>link</strong></span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>type</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"text/css"</span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>rel</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"stylesheet"</span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>media</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"screen"</span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>href</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"css/style.css"</span><span style="color:#008a8c;">&gt;</span>
<span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>head</strong></span><span style="color:#008a8c;">&gt;</span>
<span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>body</strong></span><span style="color:#008a8c;">&gt;</span>
<span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>form</strong></span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>id</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"survey"</span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>action</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"submitSurvey.php"</span><span style="color:#008a8c;">&gt;</span>
    <span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>fieldset</strong></span><span style="color:#008a8c;">&gt;</span>
        <span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>legend</strong></span><span style="color:#008a8c;">&gt;</span>Questions<span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>legend</strong></span><span style="color:#008a8c;">&gt;</span>
        <span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>p</strong></span><span style="color:#008a8c;">&gt;</span>Please rate how you feel about the following statements,
            from 0 for strongly disagree, up to 100 for strongly agree.<span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>p</strong></span><span style="color:#008a8c;">&gt;</span>
        <span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>p</strong></span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>class</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"slider"</span><span style="color:#008a8c;">&gt;&lt;</span><span style="color:#a52829;"><strong>label</strong></span><span style="color:#008a8c;">&gt;</span>
            Clowns are scary creatures
            <span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>input</strong></span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>type</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"text"</span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>name</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"clowns"</span><span style="color:#008a8c;">&gt;</span>
        <span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>label</strong></span><span style="color:#008a8c;">&gt;&lt;/</span><span style="color:#a52829;"><strong>p</strong></span><span style="color:#008a8c;">&gt;</span>
        <span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>p</strong></span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>class</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"slider"</span><span style="color:#008a8c;">&gt;&lt;</span><span style="color:#a52829;"><strong>label</strong></span><span style="color:#008a8c;">&gt;</span>
            9/11 was an inside job
            <span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>input</strong></span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>type</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"text"</span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>name</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"insidejob"</span><span style="color:#008a8c;">&gt;</span>
        <span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>label</strong></span><span style="color:#008a8c;">&gt;&lt;/</span><span style="color:#a52829;"><strong>p</strong></span><span style="color:#008a8c;">&gt;</span>
        <span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>p</strong></span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>class</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"slider"</span><span style="color:#008a8c;">&gt;&lt;</span><span style="color:#a52829;"><strong>label</strong></span><span style="color:#008a8c;">&gt;</span>
            Fox news is not a news channel
            <span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>input</strong></span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>type</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"text"</span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>name</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"foxnews"</span><span style="color:#008a8c;">&gt;</span>
        <span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>label</strong></span><span style="color:#008a8c;">&gt;&lt;/</span><span style="color:#a52829;"><strong>p</strong></span><span style="color:#008a8c;">&gt;</span>
    <span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>fieldset</strong></span><span style="color:#008a8c;">&gt;</span>
    <span style="color:#008a8c;">&lt;</span><span style="color:#a52829;"><strong>p</strong></span><span style="color:#008a8c;">&gt;&lt;</span><span style="color:#a52829;"><strong>input</strong></span><span style="color:#008a8c;"> </span><span style="color:#298a52;"><strong>type</strong></span><span style="color:#008a8c;">=</span><span style="color:#ff00ff;">"submit"</span><span style="color:#008a8c;">&gt;</span>
<span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>form</strong></span><span style="color:#008a8c;">&gt;</span>
<span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>body</strong></span><span style="color:#008a8c;">&gt;</span>
<span style="color:#008a8c;">&lt;/</span><span style="color:#a52829;"><strong>html</strong></span><span style="color:#008a8c;">&gt;</span></pre>
<p>Note that here I have chosen to use an <a href="http://www.w3.org/TR/html401/interact/forms.html#idx-label-1">implicit label</a> association instead of an <a href="http://www.w3.org/TR/html401/interact/forms.html#idx-label">explicit label</a> one.</p>
<blockquote><p>To associate a label with another control implicitly, the control element must be within the contents of the <span style="font-family:monospace;">LABEL</span> element.</p></blockquote>
<p>Using an implicit relationship means that we don&#8217;t need to add explicit identifiers to the inputs, which allows us to have cleaner code. We will find though that IE6 doesn&#8217;t understand the implicit association, however we shouldn&#8217;t be tempted into muddying the semantic meaning of our code. Especially when its sole purpose is to support a low-impact situation on a retiring web browser.</p>
<p>Now, with a little bit of styling in <code>style.css,</code> we have a form that is quite servicable in an unscripted environment.</p>
<pre><span style="color:#a52829;"><span style="font-weight:bold;">form</span></span> <span style="color:#a52829;"><span style="font-weight:bold;">label</span></span> <span style="color:#008a8c;">{</span>
    <span style="color:#298a52;"><span style="font-weight:bold;">position</span></span>: <span style="color:#298a52;"><span style="font-weight:bold;">relative</span></span>;
<span style="color:#008a8c;">}</span>
<span style="color:#a52829;"><span style="font-weight:bold;">form</span></span> <span style="color:#a52829;"><span style="font-weight:bold;">label</span></span> <span style="color:#a52829;"><span style="font-weight:bold;">input</span></span> <span style="color:#008a8c;">{</span>
    <span style="color:#298a52;"><span style="font-weight:bold;">position</span></span>: <span style="color:#298a52;"><span style="font-weight:bold;">absolute</span></span>;
    <span style="color:#298a52;"><span style="font-weight:bold;">left</span></span>: <span style="color:#ff00ff;">15em</span>;
    <span style="color:#298a52;"><span style="font-weight:bold;">width</span></span>: <span style="color:#ff00ff;">3em</span>;
<span style="color:#008a8c;">}</span></pre>
<p>This is how the slider form will look when there is no scripting available.</p>
<div id="attachment_66" class="wp-caption alignnone" style="width: 399px"><a href="http://jstricks.files.wordpress.com/2010/01/slider-form-without-javascript5.gif"><img class="size-full wp-image-66" title="slider-form-without-javascript" src="http://jstricks.files.wordpress.com/2010/01/slider-form-without-javascript5.gif?w=450" alt=""   /></a><p class="wp-caption-text">How the form looks without scripting</p></div>
<p>This takes care of any no-JavaScript situations that may occur.</p>
<p>Next: On to the <a href="http://jstricks.wordpress.com/2010/01/11/basic-requirements-for-sliders/">basic requirements for sliders</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jstricks.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jstricks.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jstricks.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jstricks.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jstricks.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jstricks.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jstricks.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jstricks.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jstricks.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jstricks.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jstricks.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jstricks.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jstricks.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jstricks.wordpress.com/32/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jstricks.wordpress.com&amp;blog=11309951&amp;post=32&amp;subd=jstricks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jstricks.wordpress.com/2010/01/11/accessible-slider-alternative/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/aacfa176a8d73ca75b90b6375151765a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Paul</media:title>
		</media:content>

		<media:content url="http://jstricks.files.wordpress.com/2010/01/slider-form-without-javascript5.gif" medium="image">
			<media:title type="html">slider-form-without-javascript</media:title>
		</media:content>
	</item>
		<item>
		<title>Introduction to sliders</title>
		<link>http://jstricks.wordpress.com/2010/01/11/introduction-to-sliders/</link>
		<comments>http://jstricks.wordpress.com/2010/01/11/introduction-to-sliders/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 02:42:53 +0000</pubDate>
		<dc:creator>Paul Wilkins</dc:creator>
				<category><![CDATA[Forms]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[jquery ui]]></category>
		<category><![CDATA[slider]]></category>

		<guid isPermaLink="false">http://jstricks.wordpress.com/?p=9</guid>
		<description><![CDATA[When creating a survey form, we may want to ask visitors how they feel about something, by using a sliding scale to indicate how they feel about things. By making use of jQuery UI, we can provide some nice sliders for our forms. This post is part of a series that guides you through creating [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jstricks.wordpress.com&amp;blog=11309951&amp;post=9&amp;subd=jstricks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When creating a survey form, we may want to ask visitors how they feel about something, by using a sliding scale to indicate how they feel about things.</p>
<p>By making use of <a href="http://jqueryui.com/">jQuery UI</a>, we can provide some nice sliders for our forms.</p>
<p>This post is part of a series that guides you through creating robust sliders for your forms.<span id="more-9"></span></p>
<ol>
<li><a href="http://jstricks.wordpress.com/2010/01/11/introduction-to-sliders/">Introduction to sliders</a> (this post)</li>
<li><a href="http://jstricks.wordpress.com/2010/01/11/accessible-slider-alternative/">Accessible slider alternative</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/11/basic-requirements-for-sliders/">Basic requirements for sliders</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/11/connecting-the-slider-to-the-form/">Connecting the slider to the form</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/12/scripting-the-slider-regions/">Scripting the slider regions</a></li>
<li><a href="http://jstricks.wordpress.com/2010/01/13/conclusion-to-sliders/">Conclusion to Sliders</a></li>
</ol>
<p>When we&#8217;re finished, this is how our form slider will look.</p>
<div id="attachment_117" class="wp-caption alignnone" style="width: 401px"><a href="http://jstricks.files.wordpress.com/2010/01/slider-form-in-use.gif"><img class="size-full wp-image-117" title="slider-form-in-use" src="http://jstricks.files.wordpress.com/2010/01/slider-form-in-use.gif?w=450" alt=""  ></a><p class="wp-caption-text">Slider form in use</p></div>
<p>To correctly make use of sliders can take some preparation, not only so that the slider value gets added to the form, but also to allow visitors without JavaScript to still be capable of using the form.</p>
<p>Before we get to the scripting part of things, we need to ensure that even when scripting is not available that the user can still use the form. This next part is about creating an accessible alternative for when scripting can not be used.</p>
<p>Next: An&nbsp;<a href="http://jstricks.wordpress.com/2010/01/11/accessible-slider-alternative/">accessible slider alternative</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jstricks.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jstricks.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jstricks.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jstricks.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jstricks.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jstricks.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jstricks.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jstricks.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jstricks.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jstricks.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jstricks.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jstricks.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jstricks.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jstricks.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jstricks.wordpress.com&amp;blog=11309951&amp;post=9&amp;subd=jstricks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jstricks.wordpress.com/2010/01/11/introduction-to-sliders/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/aacfa176a8d73ca75b90b6375151765a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Paul</media:title>
		</media:content>

		<media:content url="http://jstricks.files.wordpress.com/2010/01/slider-form-in-use.gif" medium="image">
			<media:title type="html">slider-form-in-use</media:title>
		</media:content>
	</item>
		<item>
		<title>The onbeforeunload window event</title>
		<link>http://jstricks.wordpress.com/2010/01/08/onbeforeunload/</link>
		<comments>http://jstricks.wordpress.com/2010/01/08/onbeforeunload/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 04:05:08 +0000</pubDate>
		<dc:creator>Paul Wilkins</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[window]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[The onbeforeunload event is a window event that is triggered when the window is about to close the current page.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jstricks.wordpress.com&amp;blog=11309951&amp;post=1&amp;subd=jstricks&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <code>onbeforeunload</code> event is a window event that is triggered when the window is about to close the current page. This occurs in a number of situations, including:</p>
<ul>
<li>when you use the forward or back browser buttons</li>
<li>when the page is refreshed</li>
<li>when the page is closed</li>
<li>when you click on a link to a different page</li>
</ul>
<p><span id="more-1"></span>Sometimes you will want to advise a user that they are about to lose some information that they have entered on the current page.</p>
<p>You can use the <code>onbeforeunload</code> to warn people that they may be able to lose some information</p>
<pre>window.onbeforeunload = function () {
    return 'If you leave this page you will lose the information that you have entered.';
}</pre>
<p>Note that this event differs in how it handles the return value from other JavaScript events. Most events cancel themself if you return false from them. The <code>onbeforeunload</code> event is different, in that whatever is returned (even false) is shown in the warning message.</p>
<p>While it is not possible for scripting to cancel the <code>onbeforeunload</code> event, the user will be able to choose to do so from the warning message that is shown.</p>
<p>Further details on using the <code>onbeforeunload</code> event can be found at: <a href="http://www.4guysfromrolla.com/webtech/100604-1.shtml">http://www.4guysfromrolla.com/webtech/100604-1.shtml</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jstricks.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jstricks.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jstricks.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jstricks.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jstricks.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jstricks.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jstricks.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jstricks.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jstricks.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jstricks.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jstricks.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jstricks.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jstricks.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jstricks.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jstricks.wordpress.com&amp;blog=11309951&amp;post=1&amp;subd=jstricks&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jstricks.wordpress.com/2010/01/08/onbeforeunload/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/aacfa176a8d73ca75b90b6375151765a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Paul</media:title>
		</media:content>
	</item>
	</channel>
</rss>
