<?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; prototype</title> <atom:link href="http://xavisys.com/tag/prototype/feed/" rel="self" type="application/rss+xml" /><link>http://xavisys.com</link> <description>WordPress Plugins and Custom WordPress Development</description> <lastBuildDate>Thu, 15 Jul 2010 17:58:50 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.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. $$("input[type=radio][name='radioGroupName'][value='yourDefaultValue']")[0].writeAttribute("checked", "checked"); $("someRadioGroupMember").writeAttribute("checked", "checked"); Related Posts: Using Prototype Javascript to get the [...]]]></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;">$$("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: var radioGrp = document['forms']['form_name_or_id']['radio_grp_name']; for(i=0; i &#60; radioGrp.length; i++){ if (radioGrp[i].checked == true) { var radioValue = radioGrp[i].value; } } To use it you need a reference [...]]]></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;">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;">/**
* 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;">
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>43</slash:comments> </item> <item><title>Properly degrading JavaScript Effects with Script.aculo.us</title><link>http://xavisys.com/properly-degrading-js-effects-with-scriptaculous/</link> <comments>http://xavisys.com/properly-degrading-js-effects-with-scriptaculous/#comments</comments> <pubDate>Wed, 31 Jan 2007 18:07:32 +0000</pubDate> <dc:creator>Aaron D. Campbell</dc:creator> <category><![CDATA[JavaScript]]></category> <category><![CDATA[PrototypeJS]]></category> <category><![CDATA[Script.aculo.us]]></category> <category><![CDATA[prototype]]></category><guid
isPermaLink="false">http://xavisys.com/properly-degrading-js-effects-with-scriptaculous/</guid> <description><![CDATA[I recently decided to use Script.aculo.us in a project that I&#8217;m working on. I was actually pretty impressed with it&#8217;s cross-browser compatibility and ease of use. I didn&#8217;t even think that the 200K size (including the Prototype Framework) was that bad. However, I did run into some issues while trying to make my site function [...]]]></description> <content:encoded><![CDATA[<p>I recently decided to use <a
href="http://script.aculo.us/">Script.aculo.us</a> in a project that I&#8217;m working on.  I was actually pretty impressed with it&#8217;s cross-browser compatibility and ease of use.  I didn&#8217;t even think that the 200K size (including the <a
href="http://prototypejs.org/">Prototype Framework</a>) was that bad.  However, I did run into some issues while trying to make my site function properly for users that have JavaScript disabled, while still allowing the effects for those that do.</p><p>In my particular situation, I wanted to make some objects appear with an effect.  You will notice that if you apply an Appear effect to an element, it will display, then disappear, the appear with the effect.  The solution is to set an inline style with display:none, except that this will cause the element to be missing from users without JavaScript.  The solution?  Add the display:none style with Javascript.</p><p>First, I created a CSS class called effect_appear, with no styles.</p><pre class="brush: css;">
.effect_appear {
}
</pre><p>Then I use Javascript to modify that class, and set the display to none.</p><pre class="brush: jscript;">
function getStyleClass (className) {
    if (document.styleSheets.length &lt; 1) {
        return null;
    }
    if (document.styleSheets[0].cssRules) {
        var cssRules = 'cssRules';
    } else {
        var cssRules = 'rules';
    }
    for (var s = 0; s &lt; document.styleSheets.length; s++) {
        for (var r = 0; r &lt; document.styleSheets[s][cssRules].length; r++) {
            if (document.styleSheets[s][cssRules][r].selectorText == '.' + className) {
                return document.styleSheets[s][cssRules][r];
            }
        }
    }
    return null;
}
getStyleClass('effect_appear').style.display = 'none';
</pre><p>Now, any element with that class will display normal to a user without JavaScript support,  but will be missing for users with JavaScript.  Next I added a &#8216;load&#8217; event handler to the window element, which will make the elements appear with an effect.</p><pre class="brush: jscript;">
Event.observe(window, 'load', effects);
function effects() {
    document.getElementsByClassName('effect_appear').each(
        function (el) {
            el.visualEffect('Appear');
        }
    );
}
</pre><p>However, there is still one problem.  Because the style we created is not inline, it seems to override any effect that we add.  The solution is to first remove the classname, and hide() the element (this will remove the class, but keep the element hidden, without the user ever seeing the element). Then we apply the visual effect (in this case, Appear).</p><pre class="brush: jscript;">
Event.observe(window, 'load', effects);
function effects() {
    document.getElementsByClassName('effect_appear').each(
        function (el) {
            el.removeClassName('effect_appear').hide().visualEffect('Appear');
        }
    );
}
</pre><p>Here is the whole thing.  Remember, the class  &#8220;effect_appear&#8221; MUST exist in one of your stylesheets, or in a style tag ABOVE this code.</p><pre class="brush: jscript;">
function getStyleClass (className) {
    if (document.styleSheets.length &lt; 1) {
        return null;
    }
    if (document.styleSheets[0].cssRules) {
        var cssRules = 'cssRules';
    } else {
        var cssRules = 'rules';
    }
    for (var s = 0; s &lt; document.styleSheets.length; s++) {
        for (var r = 0; r &lt; document.styleSheets[s][cssRules].length; r++) {
            if (document.styleSheets[s][cssRules][r].selectorText == '.' + className) {
                return document.styleSheets[s][cssRules][r];
            }
        }
    }
    return null;
}
getStyleClass('effect_appear').style.display = 'none';
Event.observe(window, 'load', effects);
function effects() {
    document.getElementsByClassName('effect_appear').each(
        function (el) {
            el.removeClassName('effect_appear').hide().visualEffect('Appear');
        }
    );
}
</pre><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/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/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/properly-degrading-js-effects-with-scriptaculous/feed/</wfw:commentRss> <slash:comments>20</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching using apc
Content Delivery Network via cdn.xavisys.com

Served from: xavisys.com @ 2010-09-09 11:58:08 -->