<?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>Xavisys&#187; radio</title>
	<atom:link href="http://xavisys.com/tag/radio/feed/" rel="self" type="application/rss+xml" />
	<link>http://xavisys.com</link>
	<description>WordPress Plugins and Custom WordPress Development</description>
	<lastBuildDate>Wed, 16 Nov 2011 20:45:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<atom:link rel='hub' href='http://xavisys.com/?pushpress=hub'/>
		<item>
		<title>Using Prototype Javascript to set the value of a radio group</title>
		<link>http://xavisys.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/</link>
		<comments>http://xavisys.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comments</comments>
		<pubDate>Fri, 26 Oct 2007 15:09:32 +0000</pubDate>
		<dc:creator>Aaron D. Campbell</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PrototypeJS]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[radio]]></category>

		<guid isPermaLink="false">http://xavisys.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/</guid>
		<description><![CDATA[Not that long ago I wrote Using Prototype Javascript to get the value of a radio group, but I keep getting asked how to set the value of a radio group using prototype JS. Here are a couple ways to do just that. Related Posts: Using Prototype Javascript to get the value of a radio [...]]]></description>
			<content:encoded><![CDATA[<p>Not that long ago I wrote <a href="http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/">Using Prototype Javascript to get the value of a radio group</a>, but I keep getting asked how to <strong>set</strong> the value of a radio group using <a href="http://www.prototypejs.org">prototype JS</a>.  Here are a couple ways to do just that.</p>
<pre class="brush: jscript; title: ; notranslate">$$("input[type=radio][name='radioGroupName'][value='yourDefaultValue']")[0].writeAttribute("checked", "checked");
$("someRadioGroupMember").writeAttribute("checked", "checked");</pre>
<h3 class='related_post_title'>Related Posts:</h3>
<ul class='related_post'>
<li><a href='http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/' title='Using Prototype Javascript to get the value of a radio group'>Using Prototype Javascript to get the value of a radio group</a></li>
<li><a href='http://xavisys.com/properly-degrading-js-effects-with-scriptaculous/' title='Properly degrading JavaScript Effects with Script.aculo.us'>Properly degrading JavaScript Effects with Script.aculo.us</a></li>
<li><a href='http://xavisys.com/google-maps-api/' title='Google Maps API'>Google Maps API</a></li>
<li><a href='http://xavisys.com/wordpress-script-handling/' title='Wordpress Script Handling'>WordPress Script Handling</a></li>
<li><a href='http://xavisys.com/writing-a-javascript-date-chooser/' title='My Javascript Date Chooser'>My Javascript Date Chooser</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://xavisys.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Using Prototype Javascript to get the value of a radio group</title>
		<link>http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/</link>
		<comments>http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comments</comments>
		<pubDate>Thu, 01 Mar 2007 18:59:39 +0000</pubDate>
		<dc:creator>Aaron D. Campbell</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PrototypeJS]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[radio]]></category>

		<guid isPermaLink="false">http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/</guid>
		<description><![CDATA[I am constantly asked how to find the value of the selected radio button in a radio group. The way I usually told people was something like this: To use it you need a reference to the radio group (not just a single button), which means you need to know the form, and the radio [...]]]></description>
			<content:encoded><![CDATA[<p>I am constantly asked how to find the value of the selected radio button in a radio group.  The way I usually told people was something like this:</p>
<pre class="brush: jscript; title: ; notranslate">var radioGrp = document['forms']['form_name_or_id']['radio_grp_name'];
for(i=0; i &lt; radioGrp.length; i++){
    if (radioGrp[i].checked == true) {
        var radioValue = radioGrp[i].value;
    }
}
</pre>
<p>To use it you need a reference to the radio group (not just a single button), which means you need to know the form, and the radio group name.  Since I use prototype for almost everything now, I decided to use it to make a simple function for this purpose.  First of all, here is the function:</p>
<pre class="brush: jscript; title: ; notranslate">/**
* Returns the value of the selected radio button in the radio group, null if
* none are selected, and false if the button group doesn't exist
*
* @param {radio Object} or {radio id} el
* OR
* @param {form Object} or {form id} el
* @param {radio group name} radioGroup
*/
function $RF(el, radioGroup) {
    if($(el).type &amp;&amp; $(el).type.toLowerCase() == 'radio') {
        var radioGroup = $(el).name;
        var el = $(el).form;
    } else if ($(el).tagName.toLowerCase() != 'form') {
        return false;
    }

    var checked = $(el).getInputs('radio', radioGroup).find(
        function(re) {return re.checked;}
    );
    return (checked) ? $F(checked) : null;
}</pre>
<p>You can pass it <strong>either</strong> a form (object or id) and a radio group name, <strong>or</strong> a radio button (object or id).</p>
<pre class="brush: jscript; title: ; notranslate">
var value = $RF('radio_btn_id');
var value = $RF('form_id', 'radio_grp_name');
</pre>
<p>Hopefully this will help simplify things for someone.  Maybe they will eventually add something similar into prototype itself.<br />
<h3 class='related_post_title'>Related Posts:</h3>
<ul class='related_post'>
<li><a href='http://xavisys.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/' title='Using Prototype Javascript to set the value of a radio group'>Using Prototype Javascript to set the value of a radio group</a></li>
<li><a href='http://xavisys.com/properly-degrading-js-effects-with-scriptaculous/' title='Properly degrading JavaScript Effects with Script.aculo.us'>Properly degrading JavaScript Effects with Script.aculo.us</a></li>
<li><a href='http://xavisys.com/google-maps-api/' title='Google Maps API'>Google Maps API</a></li>
<li><a href='http://xavisys.com/wordpress-script-handling/' title='Wordpress Script Handling'>WordPress Script Handling</a></li>
<li><a href='http://xavisys.com/writing-a-javascript-date-chooser/' title='My Javascript Date Chooser'>My Javascript Date Chooser</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/feed/</wfw:commentRss>
		<slash:comments>45</slash:comments>
		</item>
	</channel>
</rss>

