Print values of selected radio buttons and check-boxes and exclude the submit button
<p>In the script below, how do I get the values of only radio buttons and checkboxes that have been selected and not all (provided a radio button and checkbox were selected). </p>

<p>Right now it gives me the values of all, whether selected or not, and also the submit button (which i dont need). </p>

<p>How do i do this? There'll be more checkboxes and radio buttons, i've used only 2 sets for this question.</p>

<pre><code>&lt;html&gt; 
&lt;head&gt; 
&lt;script type="text/javascript"&gt; 
function DisplayFormValues() 
{ 
var str = ''; 
var elem = document.getElementById('frmMain').elements; 

for(var i = 0; i &lt; elem.length; i++) 
{
str += elem[i].value+"&lt;br&gt;";
} 

document.getElementById('lblValues').innerHTML = str; 
} 

&lt;/script&gt; 
&lt;/head&gt; 
&lt;body&gt; 

&lt;form id="frmMain" name="frmMain"&gt; 
&lt;INPUT TYPE="radio" NAME="r1" value="r1a"&gt;
&lt;INPUT TYPE="radio" NAME="r1" value="r1b"&gt;
&lt;INPUT TYPE="radio" NAME="r1" value="r1c"&gt;

&lt;INPUT TYPE="checkbox" NAME="c1" value="c1a"&gt;
&lt;INPUT TYPE="checkbox" NAME="c1" value="c1b"&gt;
&lt;INPUT TYPE="checkbox" NAME="c1" value="c1c"&gt;

&lt;input type="button" value="Test" onclick="DisplayFormValues();" /&gt; 
&lt;/form&gt; 
&lt;hr /&gt; 
&lt;div id="lblValues"&gt;&lt;/div&gt; 
&lt;/body&gt; 
&lt;/html&gt;
</code></pre>
