<?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>Web Lee &#187; design</title>
	<atom:link href="http://www.weblee.co.uk/tag/design/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.weblee.co.uk</link>
	<description>PHP Freelance Developer</description>
	<lastBuildDate>Sun, 19 Jul 2009 14:38:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Radio Button Replacement With Style</title>
		<link>http://www.weblee.co.uk/2009/05/30/radio-button-replacement-with-style/</link>
		<comments>http://www.weblee.co.uk/2009/05/30/radio-button-replacement-with-style/#comments</comments>
		<pubDate>Sat, 30 May 2009 00:20:28 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Jquery]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[html]]></category>

		<guid isPermaLink="false">http://www.weblee.co.uk/?p=16</guid>
		<description><![CDATA[I thought I would kick off this blog with a short tutorial on how you can make form radio buttons look and feel allot more interesting.
A recent job required the user to select a radio button which then on form submit depending on the result would load a specific page. OK im hearing you a [...]]]></description>
			<content:encoded><![CDATA[<p>I thought I would kick off this blog with a short tutorial on how you can make form radio buttons look and feel allot more interesting.</p>
<p>A recent job required the user to select a radio button which then on form submit depending on the result would load a specific page. OK im hearing you a normal set of radio buttons would have done the job fine but it just looked so boring and took up so little space. So I decided that with a bit of CSS &amp; Jquery magic we could make it look allot more interesting.</p>
<p><span id="more-16"></span></p>
<div id="action">
<ul>
<li><a class="demo" href="/demos/radio-replacement/index.html" target="_blank"><span>Demo</span></a></li>
<li><a href="http://www.weblee.co.uk/wp-content/plugins/download-monitor/download.php?id=1" class="source" title="Radio Button Replacement"><span>Radio Button Replacement</span></a> </li>
</ul>
<div class="clear-action"><span>clear</span></div>
<div class="clear-action"><span><br />
</span></div>
</div>
<p>First lets start of with a normal form with a set of radion buttons.</p>
<pre class="brush: xml;">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Fancy Checkbox&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;h2&gt;Check an Option&lt;/h2&gt;

&lt;form action=&quot;step2.html&quot; method=&quot;post&quot; id=&quot;radioform&quot;&gt;
Option 1: &lt;input name=&quot;option1&quot; type=&quot;radio&quot; value=&quot;option1&quot; id=&quot;option1&quot; checked=&quot;checked&quot; /&gt;&lt;br /&gt;
Option 2: &lt;input name=&quot;option1&quot; type=&quot;radio&quot; value=&quot;option2&quot; id=&quot;option2&quot; /&gt;&lt;br /&gt;
Option 3: &lt;input name=&quot;option1&quot; type=&quot;radio&quot; value=&quot;option3&quot; id=&quot;option3&quot; /&gt;&lt;br /&gt;
Option 4: &lt;input name=&quot;option1&quot; type=&quot;radio&quot; value=&quot;option5&quot; id=&quot;option4&quot; /&gt;&lt;br /&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Ok now we have our basic form we need to add our styled buttons and tick to show which radio button is active. I have provided in the download the PSD&#8217;s for this example but lets see the code. Below you can just see the HTML for the list elements but I have used used css sprites for the hover over / active states <em>(basically one image for both states)</em>.</p>
<pre class="brush: xml;">
&lt;div id=&quot;options&quot;&gt;
&lt;ul id=&quot;list&quot;&gt;
&lt;li class=&quot;active&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;option1 active&quot; id=&quot;link1&quot;&gt;&lt;span&gt;Option&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#&quot; class=&quot;option2&quot; id=&quot;link2&quot;&gt;&lt;span&gt;Option&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#&quot; class=&quot;option3&quot; id=&quot;link3&quot;&gt;&lt;span&gt;Option&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#&quot; class=&quot;option4&quot; id=&quot;link4&quot;&gt;&lt;span&gt;Option&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</pre>
<p>So now to the Javascript. We need to bind the click function to see which link we have clicked then update the checkbox and then update the list to reflect this action. We will use Jquery Selector <a title="Jquery Selector Hierarchy" href="http://docs.jquery.com/Selectors/child#parentchild" target="_blank">Hierarchy (parent &gt; child)</a> method which looks like this.</p>
<pre class="brush: jscript;">
$(document).ready(function () {
$(&quot;#list li &gt; a&quot;).click(function (event) {
// Work starts here
});
});
</pre>
<p>So now we have a click event function which will trigger once we click on any of the list links. We will now need to remove all active elements as trying to add/remove from each one will create extra code.</p>
<pre class="brush: jscript;">
$(document).ready(function () {

$(&quot;#list li &gt; a&quot;).live('click', function (event) {
// First disable the normal link click
event.preventDefault();

// Remove all list and links active class.
$('#list &gt; li, #list &gt; li a').removeClass(&quot;active&quot;);
return false;
});
});
</pre>
<p>Ok thats working nicely but now the fun part. We need to grad the link clicked ID and then make the correct radio button to checked and update the CSS.</p>
<pre class="brush: jscript;">
$(document).ready(function () {

$(&quot;#list li &gt; a&quot;).live('click', function (event) {
// First disable the normal link click
event.preventDefault();

// Remove all list and links active class.
$('#list .active').removeClass(&quot;active&quot;);

// Grab the link clicks ID
var id = this.id;

// The id will now be something like &quot;link1&quot;
// Now we need to replace link with option (this is the ID's of the checkbox)
var newselect = id.replace('link', 'option');

// Make newselect the option selected.
$('#'+newselect).attr('checked', true);

// Now add active state to the link and list item
$(this).addClass(&quot;active&quot;).parent().addClass(&quot;active&quot;);

return false;
});

});
</pre>
<p>And that&#8217;s it !!. You now have with just a few lines of code a nice replacement for your radio buttons.</p>
<p>Hope you enjoyed it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weblee.co.uk/2009/05/30/radio-button-replacement-with-style/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
