<?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"
	>
<channel>
	<title>Comments on: Using Prototype Javascript to get the value of a radio group</title>
	<atom:link href="http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/feed/" rel="self" type="application/rss+xml" />
	<link>http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/</link>
	<description>Control Your Internet</description>
	<pubDate>Mon, 12 May 2008 11:29:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: amiuhle</title>
		<link>http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-1521</link>
		<dc:creator>amiuhle</dc:creator>
		<pubDate>Sat, 03 May 2008 09:43:09 +0000</pubDate>
		<guid isPermaLink="false">http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-1521</guid>
		<description>I edited it a little so you can also set the value of the group:

(I also removed the second attribute, I just give the first radio in the group an ID, and that's how i reference them)

function $RG(id) {
	id = $(id);
	var ret = new Object();
	
	var groupName = id.name;
	var form = id.form;
	
	ret.radios = form.getInputs('radio', groupName);
	
	ret.getValue = function() {
		var elt = this.radios.find(function(re) {return re.checked;});
		return elt ? $F(elt) : null;
	};
	
	ret.setValue = function(value) {
		var elt = this.radios.find(function(re) {return re.value == value});
		if(elt) elt.checked = true;
	}
	
	return ret;
}</description>
		<content:encoded><![CDATA[<p>I edited it a little so you can also set the value of the group:</p>
<p>(I also removed the second attribute, I just give the first radio in the group an ID, and that&#8217;s how i reference them)</p>
<p>function $RG(id) {<br />
	id = $(id);<br />
	var ret = new Object();</p>
<p>	var groupName = id.name;<br />
	var form = id.form;</p>
<p>	ret.radios = form.getInputs(&#8217;radio&#8217;, groupName);</p>
<p>	ret.getValue = function() {<br />
		var elt = this.radios.find(function(re) {return re.checked;});<br />
		return elt ? $F(elt) : null;<br />
	};</p>
<p>	ret.setValue = function(value) {<br />
		var elt = this.radios.find(function(re) {return re.value == value});<br />
		if(elt) elt.checked = true;<br />
	}</p>
<p>	return ret;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jun Wan</title>
		<link>http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-1496</link>
		<dc:creator>Jun Wan</dc:creator>
		<pubDate>Tue, 29 Apr 2008 15:13:41 +0000</pubDate>
		<guid isPermaLink="false">http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-1496</guid>
		<description>using prototype js
if you have a group of radio button with a name says "color", the following will return the checked value of this group

$$('input:checked[type="radio"][name="color"]').pluck('value')</description>
		<content:encoded><![CDATA[<p>using prototype js<br />
if you have a group of radio button with a name says &#8220;color&#8221;, the following will return the checked value of this group</p>
<p>$$(&#8217;input:checked[type="radio"][name="color"]&#8216;).pluck(&#8217;value&#8217;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jun Wan</title>
		<link>http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-1491</link>
		<dc:creator>Jun Wan</dc:creator>
		<pubDate>Tue, 29 Apr 2008 05:18:54 +0000</pubDate>
		<guid isPermaLink="false">http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-1491</guid>
		<description>Hi Aaron, thanks for the great tips, could you please tell me how to get the selected value of each group of the radio button then?</description>
		<content:encoded><![CDATA[<p>Hi Aaron, thanks for the great tips, could you please tell me how to get the selected value of each group of the radio button then?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron D. Campbell</title>
		<link>http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-1418</link>
		<dc:creator>Aaron D. Campbell</dc:creator>
		<pubDate>Sun, 20 Apr 2008 14:37:38 +0000</pubDate>
		<guid isPermaLink="false">http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-1418</guid>
		<description>Well, this post was about using prototype, I'll show you how quickly you can do this in prototype.  To get all the input elements whose type is radio:
&lt;code lang="javascript"&gt;$$('input[type="radio"]');&lt;/code&gt;
If you want the names and not the actual elements, you can do this:
&lt;code lang="javascript"&gt;$$('input[type="radio"]').pluck('name');&lt;/code&gt;
If you want only unique names (so each group rather than each element):
&lt;code lang="javascript"&gt;$$('input[type="radio"]').pluck('name').uniq();&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Well, this post was about using prototype, I&#8217;ll show you how quickly you can do this in prototype.  To get all the input elements whose type is radio:<br />
<code lang="javascript">$$('input[type="radio"]&#8216;);</code><br />
If you want the names and not the actual elements, you can do this:<br />
<code lang="javascript">$$('input[type="radio"]&#8216;).pluck(&#8217;name&#8217;);</code><br />
If you want only unique names (so each group rather than each element):<br />
<code lang="javascript">$$('input[type="radio"]&#8216;).pluck(&#8217;name&#8217;).uniq();</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shawn S.</title>
		<link>http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-1417</link>
		<dc:creator>Shawn S.</dc:creator>
		<pubDate>Sun, 20 Apr 2008 03:51:40 +0000</pubDate>
		<guid isPermaLink="false">http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-1417</guid>
		<description>I have been getting an error stating getElementById() is an invalid method or propertie of this object/element when trying to retrieve a single input element of type RADIO with its ID...

I am attempting to create an array of all radio box groups in a form by there name. WITHOUT having a name or ID..

I am itterating throught all elements in form. If there type == radio I assign curEl.getAttribute("name") to myArray[curPos]

see below
&lt;code lang="javascript"&gt;
function validate(theForm)
{
	var errorCount = 0;
	var allErrors = "";

// THIS ARRAY WILL BE USED FOR GROUPS OF RADIO ELEMENTS FROM FORM 
//CATAGORIZED BY NAME  
var radioGroups = new Array();
//var radioGroups2 = new Array();

for (i=0; i&#60;theForm.elements.length; ++i)
{
    var curInput = theForm.elements[i];
//##########################################
// GROUP RADIO ELEMENTS FOR LATER PROCESSING               #
//                                                                                         #
//              WHAT I AM TRYING TO DO                                    #
// CHECK ALL RADIO BOXES, WITHOUT FIRST KNOWING THE  #
// NAME OF THE RADIO BOX.. MODULARIZING THE CODE TO   #
// WORK WITH ANY FORM                                                      #   
//#########################################
if (curInput.type =="radio")
{
//#######################################
// INITIAL READ AND ARRAY ASSIGNMENT/INSTANTIATION #
//######################################
   if (radioGroups.length == 0)
   {
      radioGroups[0] = curInput.getAttribute("name");
   }
//########################################
// ARRAYS HAVE BEAN INSTANTIATED, ADD PROCEEDING    #
// GROUP NAMES FOR LATER                                              #
//                   PROCESSING                                             #
//######################################
   else
   {
      var found = "false";
      for (i=0; i&#60;radioGroups.length; ++i)
      {
         if (radioGroups[i]== curInput.getAttribute("name"))
         {
            found = "true";
            i = radioGroups.length;
         } 
      }
      if (found == "false")
      {
         radioGroups[radioGroups.length] = curInput.getAttribute("name");  
      } 
			    
   }
}
}
&lt;/code&gt;
this holds up processing times out, and I can't see why it would be a never ending loop..

Is there a problem with using radioGroups.length to reset the radio groups array? I am going to try and use a holding object for radioGroups.length see if that dose the trick.</description>
		<content:encoded><![CDATA[<p>I have been getting an error stating getElementById() is an invalid method or propertie of this object/element when trying to retrieve a single input element of type RADIO with its ID&#8230;</p>
<p>I am attempting to create an array of all radio box groups in a form by there name. WITHOUT having a name or ID..</p>
<p>I am itterating throught all elements in form. If there type == radio I assign curEl.getAttribute(&#8221;name&#8221;) to myArray[curPos]</p>
<p>see below<br />
<code lang="javascript"><br />
function validate(theForm)<br />
{<br />
	var errorCount = 0;<br />
	var allErrors = "";</p>
<p>// THIS ARRAY WILL BE USED FOR GROUPS OF RADIO ELEMENTS FROM FORM<br />
//CATAGORIZED BY NAME<br />
var radioGroups = new Array();<br />
//var radioGroups2 = new Array();</p>
<p>for (i=0; i&lt;theForm.elements.length; ++i)<br />
{<br />
    var curInput = theForm.elements[i];<br />
//##########################################<br />
// GROUP RADIO ELEMENTS FOR LATER PROCESSING               #<br />
//                                                                                         #<br />
//              WHAT I AM TRYING TO DO                                    #<br />
// CHECK ALL RADIO BOXES, WITHOUT FIRST KNOWING THE  #<br />
// NAME OF THE RADIO BOX.. MODULARIZING THE CODE TO   #<br />
// WORK WITH ANY FORM                                                      #<br />
//#########################################<br />
if (curInput.type ==&#8221;radio&#8221;)<br />
{<br />
//#######################################<br />
// INITIAL READ AND ARRAY ASSIGNMENT/INSTANTIATION #<br />
//######################################<br />
   if (radioGroups.length == 0)<br />
   {<br />
      radioGroups[0] = curInput.getAttribute(&#8221;name&#8221;);<br />
   }<br />
//########################################<br />
// ARRAYS HAVE BEAN INSTANTIATED, ADD PROCEEDING    #<br />
// GROUP NAMES FOR LATER                                              #<br />
//                   PROCESSING                                             #<br />
//######################################<br />
   else<br />
   {<br />
      var found = &#8220;false&#8221;;<br />
      for (i=0; i&lt;radioGroups.length; ++i)<br />
      {<br />
         if (radioGroups[i]== curInput.getAttribute(&#8221;name&#8221;))<br />
         {<br />
            found = &#8220;true&#8221;;<br />
            i = radioGroups.length;<br />
         }<br />
      }<br />
      if (found == &#8220;false&#8221;)<br />
      {<br />
         radioGroups[radioGroups.length] = curInput.getAttribute(&#8221;name&#8221;);<br />
      } </p>
<p>   }<br />
}<br />
}<br />
</code><br />
this holds up processing times out, and I can&#8217;t see why it would be a never ending loop..</p>
<p>Is there a problem with using radioGroups.length to reset the radio groups array? I am going to try and use a holding object for radioGroups.length see if that dose the trick.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard Hart</title>
		<link>http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-1388</link>
		<dc:creator>Richard Hart</dc:creator>
		<pubDate>Mon, 14 Apr 2008 21:11:38 +0000</pubDate>
		<guid isPermaLink="false">http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-1388</guid>
		<description>Great! Thanks for sharing.</description>
		<content:encoded><![CDATA[<p>Great! Thanks for sharing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vrann</title>
		<link>http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-1354</link>
		<dc:creator>vrann</dc:creator>
		<pubDate>Mon, 17 Mar 2008 09:32:32 +0000</pubDate>
		<guid isPermaLink="false">http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-1354</guid>
		<description>I use it)</description>
		<content:encoded><![CDATA[<p>I use it)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andres</title>
		<link>http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-1353</link>
		<dc:creator>Andres</dc:creator>
		<pubDate>Sun, 16 Mar 2008 23:58:42 +0000</pubDate>
		<guid isPermaLink="false">http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-1353</guid>
		<description>Great function. i think it should be included in the next version of prototype</description>
		<content:encoded><![CDATA[<p>Great function. i think it should be included in the next version of prototype</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron D. Campbell</title>
		<link>http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-468</link>
		<dc:creator>Aaron D. Campbell</dc:creator>
		<pubDate>Wed, 24 Oct 2007 14:42:12 +0000</pubDate>
		<guid isPermaLink="false">http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-468</guid>
		<description>&lt;p&gt;Sorry, I was on vacation.  Here are solutions similar to yours:&lt;/p&gt;
&lt;code&gt;$$("input[type=radio][name='radioGroupName'][value='yourDefaultValue']").writeAttribute("checked", "checked");
$("someRadioGroupMember").writeAttribute("checked", "checked");&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Sorry, I was on vacation.  Here are solutions similar to yours:</p>
<p><code>$$("input[type=radio][name='radioGroupName'][value='yourDefaultValue']&#8220;).writeAttribute(&#8221;checked&#8221;, &#8220;checked&#8221;);<br />
$(&#8221;someRadioGroupMember&#8221;).writeAttribute(&#8221;checked&#8221;, &#8220;checked&#8221;);</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ville Walveranta</title>
		<link>http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-465</link>
		<dc:creator>Ville Walveranta</dc:creator>
		<pubDate>Sun, 21 Oct 2007 04:21:57 +0000</pubDate>
		<guid isPermaLink="false">http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/#comment-465</guid>
		<description>But how to *set* radio group value and selected button in prototype?

In other words, I'm looking for the prototype equivalent for jQuery's...
&lt;code&gt;
$("#some_radio_group").val("myDefaultValue");
$("#some_radio_group_member1").attr("checked", "checked");
&lt;/code&gt;

Probably (?) easy; I just started using prototype two days ago, and haven't figured this one out yet :). Thanks for any insights.</description>
		<content:encoded><![CDATA[<p>But how to *set* radio group value and selected button in prototype?</p>
<p>In other words, I&#8217;m looking for the prototype equivalent for jQuery&#8217;s&#8230;<br />
<code><br />
$("#some_radio_group").val("myDefaultValue");<br />
$("#some_radio_group_member1").attr("checked", "checked");<br />
</code></p>
<p>Probably (?) easy; I just started using prototype two days ago, and haven&#8217;t figured this one out yet :). Thanks for any insights.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
