<?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: Using Prototype Javascript to set the value of a radio group</title>
	<atom:link href="http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/feed/" rel="self" type="application/rss+xml" />
	<link>http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-prototype-javascript-to-set-the-value-of-a-radio-group</link>
	<description>BlueDog Web Services</description>
	<lastBuildDate>Wed, 09 May 2012 20:39:59 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-beta3</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Ben Greiner</title>
		<link>http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-124</link>
		<dc:creator>Ben Greiner</dc:creator>
		<pubDate>Tue, 22 Dec 2009 22:48:58 +0000</pubDate>
		<guid isPermaLink="false">http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-124</guid>
		<description>Something else to note.. After doing more testing. I discovered that if the value is already set, it appears that the Aaron&#039;s solution does not change the values. In this scenario the radio buttons load run the js script and set their values, GREAT! Now the user comes along and changes the values.. but users being indecisive, decides he doesn&#039;t want to change them after all and instead clicks cancel. This will then reset those radio buttons by running the same bit of code, and restoring cached values of the original state. I have discovered that my solution will actually reset those values.</description>
		<content:encoded><![CDATA[<p>Something else to note.. After doing more testing. I discovered that if the value is already set, it appears that the Aaron&#8217;s solution does not change the values. In this scenario the radio buttons load run the js script and set their values, GREAT! Now the user comes along and changes the values.. but users being indecisive, decides he doesn&#8217;t want to change them after all and instead clicks cancel. This will then reset those radio buttons by running the same bit of code, and restoring cached values of the original state. I have discovered that my solution will actually reset those values.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Greiner</title>
		<link>http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-123</link>
		<dc:creator>Ben Greiner</dc:creator>
		<pubDate>Tue, 22 Dec 2009 22:17:05 +0000</pubDate>
		<guid isPermaLink="false">http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-123</guid>
		<description>Oh well now you made me curious.. I did some basic benchmarking. 

Now on my main Ubuntu machine, it was dead even. 1 millisecond execution time. Not a surprise the thing is a quad core screamer.  I ran it with my Dual Core Mac Book Pro and got the follow results..

I had three sets of Option Boxes Each with two Options..

This was with my solution.
1261519984835
1261519984836
1
1261519984906
1261519984908
2
1261519984977
1261519984978
1

With the modified version of your solution..
 1261519929799
1261519929800
1
1261519929868
1261519929869
1
1261519929941
1261519929942
1
 
So the results are in and your solution has it by 1 millisecond! 

If anyone else would like to try it out..

function $RFS(radioGroup, value) {
	      	var date1 = new Date();
			var milliseconds1 = date1.getTime();
	      
	      	//$$(&quot;&#039;input[type=radio][name=&#039;&quot; + radioGroup + &quot;&#039;][value=&#039;&quot; + value + &quot;&#039;]&quot;)[0].writeAttribute(&#039;checked&#039;, &#039;checked&#039;);
			
	      	if(curRadio = $$(&#039;input[type=radio]&#039;).detect( function isRadioGroup(group){
	      		if(group.getAttribute(&#039;id&#039;) == $(radioGroup).getAttribute(&#039;id&#039;) &amp;&amp;  group.value == value){	return true;}
	      	})){ curRadio.checked = true; }
	      	
	      	var date2 = new Date();
			var milliseconds2 = date2.getTime();
			
			var difference = milliseconds2 - milliseconds1; 
			console.log(milliseconds1);
			console.log(milliseconds2);
			console.log(difference);
	      	
	      }</description>
		<content:encoded><![CDATA[<p>Oh well now you made me curious.. I did some basic benchmarking. </p>
<p>Now on my main Ubuntu machine, it was dead even. 1 millisecond execution time. Not a surprise the thing is a quad core screamer.  I ran it with my Dual Core Mac Book Pro and got the follow results..</p>
<p>I had three sets of Option Boxes Each with two Options..</p>
<p>This was with my solution.<br />
1261519984835<br />
1261519984836<br />
1<br />
1261519984906<br />
1261519984908<br />
2<br />
1261519984977<br />
1261519984978<br />
1</p>
<p>With the modified version of your solution..<br />
 1261519929799<br />
1261519929800<br />
1<br />
1261519929868<br />
1261519929869<br />
1<br />
1261519929941<br />
1261519929942<br />
1</p>
<p>So the results are in and your solution has it by 1 millisecond! </p>
<p>If anyone else would like to try it out..</p>
<p>function $RFS(radioGroup, value) {<br />
	      	var date1 = new Date();<br />
			var milliseconds1 = date1.getTime();</p>
<p>	      	//$$(&#8220;&#8216;input[type=radio][name='" + radioGroup + "'][value='" + value + "']&#8220;)[0].writeAttribute(&#8216;checked&#8217;, &#8216;checked&#8217;);</p>
<p>	      	if(curRadio = $$(&#8216;input[type=radio]&#8216;).detect( function isRadioGroup(group){<br />
	      		if(group.getAttribute(&#8216;id&#8217;) == $(radioGroup).getAttribute(&#8216;id&#8217;) &amp;&amp;  group.value == value){	return true;}<br />
	      	})){ curRadio.checked = true; }</p>
<p>	      	var date2 = new Date();<br />
			var milliseconds2 = date2.getTime();</p>
<p>			var difference = milliseconds2 &#8211; milliseconds1;<br />
			console.log(milliseconds1);<br />
			console.log(milliseconds2);<br />
			console.log(difference);</p>
<p>	      }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Greiner</title>
		<link>http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-122</link>
		<dc:creator>Ben Greiner</dc:creator>
		<pubDate>Tue, 22 Dec 2009 21:53:24 +0000</pubDate>
		<guid isPermaLink="false">http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-122</guid>
		<description>But you make an interesting point.. I hadn&#039;t thought about delimiting the double quotes and just plug in my vars.. The obvious often eludes me..

$$(&quot;&#039;input[type=radio][name=&#039; &quot; + radioGroup + &quot; &#039;][value=&#039; &quot; + value + &quot; &#039;]&quot;)[0].writeAttribute(&#039;checked&#039;, &#039;checked&#039;);

This also works.. But to answer your initial question.. I don&#039;t know which version would be faster, though yours is certainly more compact. That would be something interesting to find out certainly.. but alas.. I must be moving on. Think I will use your modified solution for now ;-)</description>
		<content:encoded><![CDATA[<p>But you make an interesting point.. I hadn&#8217;t thought about delimiting the double quotes and just plug in my vars.. The obvious often eludes me..</p>
<p>$$(&#8220;&#8216;input[type=radio][name=' " + radioGroup + " '][value=' " + value + " ']&#8220;)[0].writeAttribute(&#8216;checked&#8217;, &#8216;checked&#8217;);</p>
<p>This also works.. But to answer your initial question.. I don&#8217;t know which version would be faster, though yours is certainly more compact. That would be something interesting to find out certainly.. but alas.. I must be moving on. Think I will use your modified solution for now ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Greiner</title>
		<link>http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-121</link>
		<dc:creator>Ben Greiner</dc:creator>
		<pubDate>Tue, 22 Dec 2009 21:42:12 +0000</pubDate>
		<guid isPermaLink="false">http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-121</guid>
		<description>I was unable to get the multiple selects input[type=radio][name=varName] to return valid values.. Always came back empty. I am using a Prototype class in an external js file that has all the field names passed in as constructor options. When I passed name=this.options.fieldName it seemed to take it as a literal instead of a var. So that would be why I had to do a little work around here..</description>
		<content:encoded><![CDATA[<p>I was unable to get the multiple selects input[type=radio][name=varName] to return valid values.. Always came back empty. I am using a Prototype class in an external js file that has all the field names passed in as constructor options. When I passed name=this.options.fieldName it seemed to take it as a literal instead of a var. So that would be why I had to do a little work around here..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Greiner</title>
		<link>http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-120</link>
		<dc:creator>Ben Greiner</dc:creator>
		<pubDate>Tue, 22 Dec 2009 21:38:05 +0000</pubDate>
		<guid isPermaLink="false">http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-120</guid>
		<description>Ooops Small gaff.. This is the correct function.. My Bad..

function $RFS(radioGroup, value) {
	      	if(curRadio = $$(&#039;input[type=radio]&#039;).detect( function isRadioGroup(group){
	      		if(group.getAttribute(&#039;id&#039;) == $(radioGroup).getAttribute(&#039;id&#039;) &amp;&amp; group.value == value){	return true;}
	      	})){ curRadio.checked = true; }
}</description>
		<content:encoded><![CDATA[<p>Ooops Small gaff.. This is the correct function.. My Bad..</p>
<p>function $RFS(radioGroup, value) {<br />
	      	if(curRadio = $$(&#8216;input[type=radio]&#8216;).detect( function isRadioGroup(group){<br />
	      		if(group.getAttribute(&#8216;id&#8217;) == $(radioGroup).getAttribute(&#8216;id&#8217;) &amp;&amp; group.value == value){	return true;}<br />
	      	})){ curRadio.checked = true; }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AaronCampbell</title>
		<link>http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-119</link>
		<dc:creator>AaronCampbell</dc:creator>
		<pubDate>Tue, 22 Dec 2009 20:59:35 +0000</pubDate>
		<guid isPermaLink="false">http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-119</guid>
		<description>Thanks for the input.  Do you think that&#039;s going to be as efficient as:
[code lang=&quot;javascript&quot;]$$(&quot;input[type=radio][name=&#039;radioGroupName&#039;][value=&#039;yourDefaultValue&#039;]&quot;)[0].writeAttribute(&quot;checked&quot;, &quot;checked&quot;);[/code] </description>
		<content:encoded><![CDATA[<p>Thanks for the input.  Do you think that&#8217;s going to be as efficient as:</p>
<pre class="brush: jscript; title: ; notranslate">$$(&amp;quot;input[type=radio][name='radioGroupName'][value='yourDefaultValue']&amp;quot;)[0].writeAttribute(&amp;quot;checked&amp;quot;, &amp;quot;checked&amp;quot;);</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Greiner</title>
		<link>http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-118</link>
		<dc:creator>Ben Greiner</dc:creator>
		<pubDate>Tue, 22 Dec 2009 20:50:11 +0000</pubDate>
		<guid isPermaLink="false">http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-118</guid>
		<description>Gosh guess I actually have to do the heavy lifting myself here. This is with Prototype 1.8.3.. Though I see no reason why this wouldn&#039;t work with older prototype versions. Enjoy ;o)~

[code lang=&quot;javascript&quot;]
function $RFS(radioGroup, value) {
	if( curRadio = $$(&#039;input[type=radio]&#039;).detect( function isRadioGroup(group){
		if(group == $(radioGroup) &amp;&amp; group.value == value){return true;}
	})){ curRadio.checked = true; }
}
[/code]

* comment edited by admin to use the `code` shortcode around the source code snippet</description>
		<content:encoded><![CDATA[<p>Gosh guess I actually have to do the heavy lifting myself here. This is with Prototype 1.8.3.. Though I see no reason why this wouldn&#8217;t work with older prototype versions. Enjoy ;o)~</p>
<pre class="brush: jscript; title: ; notranslate">
function $RFS(radioGroup, value) {
	if( curRadio = $$('input[type=radio]').detect( function isRadioGroup(group){
		if(group == $(radioGroup) &amp;amp;&amp;amp; group.value == value){return true;}
	})){ curRadio.checked = true; }
}
</pre>
<p>* comment edited by admin to use the `code` shortcode around the source code snippet</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron D. Campbell</title>
		<link>http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-117</link>
		<dc:creator>Aaron D. Campbell</dc:creator>
		<pubDate>Mon, 16 Jun 2008 18:58:50 +0000</pubDate>
		<guid isPermaLink="false">http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-117</guid>
		<description>Rob: Sorry, there was a mistake in that.  there should have been a &quot;[0]&quot; following the $$().  Try it with the updated code.</description>
		<content:encoded><![CDATA[<p>Rob: Sorry, there was a mistake in that.  there should have been a &#8220;[0]&#8221; following the $$().  Try it with the updated code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob</title>
		<link>http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-116</link>
		<dc:creator>Rob</dc:creator>
		<pubDate>Mon, 16 Jun 2008 18:46:58 +0000</pubDate>
		<guid isPermaLink="false">http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-116</guid>
		<description>It didn&#039;t work for me either

$$(&quot;input[type=radio][name=&#039;groupname&#039;][value=&#039;myvalue&#039;]&quot;).writeAttribute is not a function

Prototype 1.6.0</description>
		<content:encoded><![CDATA[<p>It didn&#8217;t work for me either</p>
<p>$$(&#8220;input[type=radio][name='groupname'][value='myvalue']&#8220;).writeAttribute is not a function</p>
<p>Prototype 1.6.0</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron D. Campbell</title>
		<link>http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-115</link>
		<dc:creator>Aaron D. Campbell</dc:creator>
		<pubDate>Fri, 01 Feb 2008 17:53:24 +0000</pubDate>
		<guid isPermaLink="false">http://bluedogwebservices.com/using-prototype-javascript-to-set-the-value-of-a-radio-group/#comment-115</guid>
		<description>What version of Prototype were you using?</description>
		<content:encoded><![CDATA[<p>What version of Prototype were you using?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

