<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Posts about Radiobutton</title>
    <link>http://wiki.futuretoby.com/tag/radiobutton</link>
    <language>en-us</language>
    <item>
      <title>Radio Buttons Simplified</title>
      <description>Working with radio buttons in javascript has always been a pain, even with the help of jQuery. For example, if you have something like:&lt;pre&gt;&amp;lt;label&amp;gt;Yes: &amp;lt;/label&amp;gt;&lt;/pre&gt;&lt;pre&gt;&amp;lt;input type="radio" name="yes_no" value="yes"&amp;gt;&amp;lt;br&amp;gt;&lt;/pre&gt;&lt;pre&gt;&amp;lt;label&amp;gt;No: &amp;lt;/label&amp;gt;&lt;/pre&gt;&lt;pre&gt;&amp;lt;input type="radio" name="yes_no" value="no"&amp;gt;&lt;/pre&gt;&lt;div&gt;First, it is tedious, bordering non-trivial to get the get the current value of this radio selection group: &lt;i&gt;is it yes or no?&lt;/i&gt;&lt;/div&gt;&lt;div&gt;Second, it is also tedious, bordering non-trivial to listen for changes to the value, especially given the different behaviors of different browsers(&lt;i&gt;IE does not emit a change event when you click on a radio button to change it until you blur from it&lt;/i&gt;).&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;I wrote a tiny jQuery library to make this easier, with which you can do:&lt;/div&gt;&lt;pre&gt;&amp;gt; $.radio('yes_no').val()&lt;/pre&gt;&lt;pre&gt;'yes'&lt;/pre&gt;&lt;div&gt;to get the selected value, and to listen for changes:&lt;/div&gt;&lt;pre&gt;&amp;gt; $.radio('yes_no').change(function(ui){&lt;/pre&gt;&lt;pre&gt;    console.log('yes_no value changed to ' + ui.val());&lt;/pre&gt;&lt;pre&gt;})&lt;/pre&gt;&lt;div&gt;That's as simple as it gets. Code is as usual, on&amp;nbsp;&lt;a href="http://github.com/airportyh/jRadio/tree/master"&gt;github&lt;/a&gt;.&lt;/div&gt;</description>
      <pubDate>Sun, 19 Jul 2009 22:10:35 -0500</pubDate>
      <guid>http://wiki.futuretoby.com/Radio_Buttons_Simplified</guid>
      <author>toby ho</author>
      <link>http://wiki.futuretoby.com/Radio_Buttons_Simplified</link>
    </item>
  </channel>
</rss>

