<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Usable multiple-selection with checkbox lists and jQuery</title>
	<atom:link href="http://www.joelanman.com/2009/03/simple-multiple-selection-with-checkbox-lists-and-jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.joelanman.com/2009/03/simple-multiple-selection-with-checkbox-lists-and-jquery/</link>
	<description>Web design and development when not playing computer games</description>
	<lastBuildDate>Thu, 20 Oct 2011 11:10:55 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Remi Roques</title>
		<link>http://www.joelanman.com/2009/03/simple-multiple-selection-with-checkbox-lists-and-jquery/#comment-389</link>
		<dc:creator>Remi Roques</dc:creator>
		<pubDate>Tue, 19 Apr 2011 23:32:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.joelanman.com/?p=11#comment-389</guid>
		<description>For IE6/7, try that CSS: got rid of the 26px, padding and the posititon attributes.


body {
	padding: 40px;
	font-family: Arial, Helvetica, sans-serif;
}

h1 {
	font-size: 1em;
}

ul#albums {
	width: 220px;
	height: 160px;
	overflow-y: auto;
	overflow-x: hidden;
	list-style: none;
	padding: 0;
	border: 1px solid #CCC;
}

#albums li label {
	display: block;
	border-bottom: 1px solid #DDD;
	padding: 4px 4px 4px 4px;
	color: #000;
	outline: none;
}

#albums li label:hover {
	color: #000;
	background-color: #EEE;
}

#albums li label.selected {
	color: #FFF;
	background-color: #CCC;
}

#albums li label .checkbox {
	top: 2px;
	left: 2px;
}</description>
		<content:encoded><![CDATA[<p>For IE6/7, try that CSS: got rid of the 26px, padding and the posititon attributes.</p>
<p>body {<br />
	padding: 40px;<br />
	font-family: Arial, Helvetica, sans-serif;<br />
}</p>
<p>h1 {<br />
	font-size: 1em;<br />
}</p>
<p>ul#albums {<br />
	width: 220px;<br />
	height: 160px;<br />
	overflow-y: auto;<br />
	overflow-x: hidden;<br />
	list-style: none;<br />
	padding: 0;<br />
	border: 1px solid #CCC;<br />
}</p>
<p>#albums li label {<br />
	display: block;<br />
	border-bottom: 1px solid #DDD;<br />
	padding: 4px 4px 4px 4px;<br />
	color: #000;<br />
	outline: none;<br />
}</p>
<p>#albums li label:hover {<br />
	color: #000;<br />
	background-color: #EEE;<br />
}</p>
<p>#albums li label.selected {<br />
	color: #FFF;<br />
	background-color: #CCC;<br />
}</p>
<p>#albums li label .checkbox {<br />
	top: 2px;<br />
	left: 2px;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: remi</title>
		<link>http://www.joelanman.com/2009/03/simple-multiple-selection-with-checkbox-lists-and-jquery/#comment-387</link>
		<dc:creator>remi</dc:creator>
		<pubDate>Tue, 19 Apr 2011 04:07:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.joelanman.com/?p=11#comment-387</guid>
		<description>Hi there. Interesting UI. I join Eno: any idea for a fix for IE6/7 ?</description>
		<content:encoded><![CDATA[<p>Hi there. Interesting UI. I join Eno: any idea for a fix for IE6/7 ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eno bassey</title>
		<link>http://www.joelanman.com/2009/03/simple-multiple-selection-with-checkbox-lists-and-jquery/#comment-294</link>
		<dc:creator>eno bassey</dc:creator>
		<pubDate>Mon, 10 Jan 2011 08:20:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.joelanman.com/?p=11#comment-294</guid>
		<description>hi thanks for this it actually helped me out but wen i view in ie7 or ie6 it doesnt work why?</description>
		<content:encoded><![CDATA[<p>hi thanks for this it actually helped me out but wen i view in ie7 or ie6 it doesnt work why?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason Grant</title>
		<link>http://www.joelanman.com/2009/03/simple-multiple-selection-with-checkbox-lists-and-jquery/#comment-65</link>
		<dc:creator>Jason Grant</dc:creator>
		<pubDate>Tue, 22 Jun 2010 08:37:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.joelanman.com/?p=11#comment-65</guid>
		<description>I have been looking for something along these lines for decades now! Thanks!</description>
		<content:encoded><![CDATA[<p>I have been looking for something along these lines for decades now! Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Viktor</title>
		<link>http://www.joelanman.com/2009/03/simple-multiple-selection-with-checkbox-lists-and-jquery/#comment-8</link>
		<dc:creator>Viktor</dc:creator>
		<pubDate>Fri, 10 Apr 2009 05:32:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.joelanman.com/?p=11#comment-8</guid>
		<description>Thanks for the reply!
I&#039;m beginner in Web and JavaScript programming and tips :)</description>
		<content:encoded><![CDATA[<p>Thanks for the reply!<br />
I&#8217;m beginner in Web and JavaScript programming and tips :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.joelanman.com/2009/03/simple-multiple-selection-with-checkbox-lists-and-jquery/#comment-7</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Thu, 09 Apr 2009 08:55:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.joelanman.com/?p=11#comment-7</guid>
		<description>Hi Victor, thanks for the comment.

The problem with the code you posted is two-fold: it assumes the link already has the correct class for its state, and it flips the checkbox state based on the current state.

The problem with the first is that a lot of browsers try to maintain the state of the form on refresh. This means that if you tick some boxes and then refresh, the selected items would be ticked, but not have the correct class. With your code, if you then clicked, it would toggle to the wrong class again. The solution to this would be to make sure the items have the correct class when the page loads - I&#039;ll look into adding that.

The problem with the second is that we deal with two different events - clicking the link and clicking the checkbox itself. When you click the checkbox, it changes state automatically before this code gets run. Therefore if you simply toggle the state, it will toggle back to its original state. If you try using preventDefault(), the checkbox will still change state before the code is run, the code will toggle it off again, and then the preventDefault() runs, also turning it off (preventing the default behaviour) so it doesn&#039;t help. This is why I treat the link and the checkbox event separately and pass the desired state to applyChecked().

If we implement the class checking on page load as I mentioned earlier, then the following code should work:

$link.toggleClass(’selected’);
$checkbox.attr(’checked’, checked);</description>
		<content:encoded><![CDATA[<p>Hi Victor, thanks for the comment.</p>
<p>The problem with the code you posted is two-fold: it assumes the link already has the correct class for its state, and it flips the checkbox state based on the current state.</p>
<p>The problem with the first is that a lot of browsers try to maintain the state of the form on refresh. This means that if you tick some boxes and then refresh, the selected items would be ticked, but not have the correct class. With your code, if you then clicked, it would toggle to the wrong class again. The solution to this would be to make sure the items have the correct class when the page loads &#8211; I&#8217;ll look into adding that.</p>
<p>The problem with the second is that we deal with two different events &#8211; clicking the link and clicking the checkbox itself. When you click the checkbox, it changes state automatically before this code gets run. Therefore if you simply toggle the state, it will toggle back to its original state. If you try using preventDefault(), the checkbox will still change state before the code is run, the code will toggle it off again, and then the preventDefault() runs, also turning it off (preventing the default behaviour) so it doesn&#8217;t help. This is why I treat the link and the checkbox event separately and pass the desired state to applyChecked().</p>
<p>If we implement the class checking on page load as I mentioned earlier, then the following code should work:</p>
<p>$link.toggleClass(’selected’);<br />
$checkbox.attr(’checked’, checked);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Viktor</title>
		<link>http://www.joelanman.com/2009/03/simple-multiple-selection-with-checkbox-lists-and-jquery/#comment-6</link>
		<dc:creator>Viktor</dc:creator>
		<pubDate>Thu, 09 Apr 2009 04:25:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.joelanman.com/?p=11#comment-6</guid>
		<description>Hi!

if (checked)
{
$link.addClass(&#039;selected&#039;);
$checkbox.attr(&#039;checked&#039;, true);
} else {
$link.removeClass(&#039;selected&#039;);
$checkbox.attr(&#039;checked&#039;, false);
}

==

$link.toggleClass(&#039;selected&#039;);
$checkbox.attr(&#039;checked&#039;, !($checkbox.attr(&#039;checked&#039;)));


?</description>
		<content:encoded><![CDATA[<p>Hi!</p>
<p>if (checked)<br />
{<br />
$link.addClass(&#8216;selected&#8217;);<br />
$checkbox.attr(&#8216;checked&#8217;, true);<br />
} else {<br />
$link.removeClass(&#8216;selected&#8217;);<br />
$checkbox.attr(&#8216;checked&#8217;, false);<br />
}</p>
<p>==</p>
<p>$link.toggleClass(&#8216;selected&#8217;);<br />
$checkbox.attr(&#8216;checked&#8217;, !($checkbox.attr(&#8216;checked&#8217;)));</p>
<p>?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.471 seconds -->

