<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
   <channel>
      <title>Pseudointellectual Appendification</title>
      <link>http://www.mischievous.org/</link>
      <description>Able or tending to cause annoyance, trouble, or minor injury.</description>
      <language>en-US</language>
      <copyright>Copyright 2008</copyright>
      <lastBuildDate>Tue, 20 Jun 2006 10:09:24 -0800</lastBuildDate>
      <generator>http://www.sixapart.com/movabletype/</generator>
      <docs>http://blogs.law.harvard.edu/tech/rss</docs>
      
      <item>
         <title>Using MochiKit to Move Items Between Select Lists</title>
         <description><![CDATA[If you are writing client side JavaScript you should be using <a class="external" href="http://mochikit.com/">MochiKit</a>.
I found myself needing to implement two select list boxes where items
are moved from one to the other. I was able to implement this with some
very concise JavaScript thanks to MochiKit's functional programming and
DOM manipulation APIs. <pre><tt>    <span style="font-weight: bold;"><span style="color: rgb(0, 0, 255);">function</span></span> <span style="font-weight: bold;"><span style="color: rgb(0, 0, 0);">makeOption</span></span><span style="color: rgb(153, 0, 0);">(</span>option<span style="color: rgb(153, 0, 0);">)</span> <span style="color: rgb(255, 0, 0);">{</span><br>      <span style="font-weight: bold;"><span style="color: rgb(0, 0, 255);">return</span></span> <span style="font-weight: bold;"><span style="color: rgb(0, 0, 0);">OPTION</span></span><span style="color: rgb(153, 0, 0);">(</span><span style="color: rgb(255, 0, 0);">{</span><span style="color: rgb(255, 0, 0);">"value"</span><span style="color: rgb(153, 0, 0);">:</span> option<span style="color: rgb(153, 0, 0);">.</span>value<span style="color: rgb(255, 0, 0);">}</span><span style="color: rgb(153, 0, 0);">,</span> option<span style="color: rgb(153, 0, 0);">.</span>text<span style="color: rgb(153, 0, 0);">)</span><span style="color: rgb(153, 0, 0);">;</span><br>    <span style="color: rgb(255, 0, 0);">}</span><br>     <br>    <span style="font-weight: bold;"><span style="color: rgb(0, 0, 255);">function</span></span> <span style="font-weight: bold;"><span style="color: rgb(0, 0, 0);">moveOption</span></span><span style="color: rgb(153, 0, 0);">(</span> fromSelect<span style="color: rgb(153, 0, 0);">,</span> toSelect<span style="color: rgb(153, 0, 0);">)</span><br>    <span style="color: rgb(255, 0, 0);">{</span><br>      <span style="font-style: italic;"><span style="color: rgb(154, 25, 0);">// add 'selected' nodes toSelect</span></span><br>      <span style="font-weight: bold;"><span style="color: rgb(0, 0, 0);">appendChildNodes</span></span><span style="color: rgb(153, 0, 0);">(</span>toSelect<span style="color: rgb(153, 0, 0);">,</span><br>        <span style="font-weight: bold;"><span style="color: rgb(0, 0, 0);">map</span></span><span style="color: rgb(153, 0, 0);">(</span> makeOption<span style="color: rgb(153, 0, 0);">,</span><br>          <span style="font-weight: bold;"><span style="color: rgb(0, 0, 0);">ifilter</span></span><span style="color: rgb(153, 0, 0);">(</span><span style="font-weight: bold;"><span style="color: rgb(0, 0, 0);">itemgetter</span></span><span style="color: rgb(153, 0, 0);">(</span><span style="color: rgb(255, 0, 0);">'selected'</span><span style="color: rgb(153, 0, 0);">)</span><span style="color: rgb(153, 0, 0);">,</span> $<span style="color: rgb(153, 0, 0);">(</span>fromSelect<span style="color: rgb(153, 0, 0);">)</span><span style="color: rgb(153, 0, 0);">.</span>options<span style="color: rgb(153, 0, 0);">)</span><span style="color: rgb(153, 0, 0);">)</span><br>      <span style="color: rgb(153, 0, 0);">)</span><span style="color: rgb(153, 0, 0);">;</span><br><br>      <span style="font-style: italic;"><span style="color: rgb(154, 25, 0);">// remove the 'selected' fromSelect</span></span><br>      <span style="font-weight: bold;"><span style="color: rgb(0, 0, 0);">replaceChildNodes</span></span><span style="color: rgb(153, 0, 0);">(</span>fromSelect<span style="color: rgb(153, 0, 0);">,</span><br>        <span style="font-weight: bold;"><span style="color: rgb(0, 0, 0);">list</span></span><span style="color: rgb(153, 0, 0);">(</span><span style="font-weight: bold;"><span style="color: rgb(0, 0, 0);">ifilterfalse</span></span><span style="color: rgb(153, 0, 0);">(</span><span style="font-weight: bold;"><span style="color: rgb(0, 0, 0);">itemgetter</span></span><span style="color: rgb(153, 0, 0);">(</span><span style="color: rgb(255, 0, 0);">'selected'</span><span style="color: rgb(153, 0, 0);">)</span><span style="color: rgb(153, 0, 0);">,</span> $<span style="color: rgb(153, 0, 0);">(</span>fromSelect<span style="color: rgb(153, 0, 0);">)</span><span style="color: rgb(153, 0, 0);">.</span>options<span style="color: rgb(153, 0, 0);">)</span><span style="color: rgb(153, 0, 0);">)</span><br>      <span style="color: rgb(153, 0, 0);">)</span><span style="color: rgb(153, 0, 0);">;</span><br>    <span style="color: rgb(255, 0, 0);">}</span>
</tt></pre><p>
You can see a <a href="../../l/mochikit.select.example">working example</a>.
</p><p>
There are <a class="external" href="http://www.mattkruse.com/javascript/selectbox/source.html">longer and more complete</a> examples out there, but you should be able to implement all of the functionality that they provide using MochiKit.</p> ]]></description>
         <link>http://www.mischievous.org/2006/06/using_mochikit_to_move_items_b.html</link>
         <guid>http://www.mischievous.org/2006/06/using_mochikit_to_move_items_b.html</guid>
        
        
          <category domain="http://www.sixapart.com/ns/types#tag">mochikit</category>
        
         <pubDate>Tue, 20 Jun 2006 10:09:24 -0800</pubDate>
      </item>
      
   </channel>
</rss>
