Get value of selected radio button without knowing form id nor how much forms is there in a page
<p>I am looking for a safe way to get value of a selected radio button :</p>

<ul>
<li>I do not know the form id</li>
<li>I do not know how much similar (ids excluded) form I have in my page</li>
</ul>

<p>I am currently using this :</p>

<pre><code>if (($(elem).is('input[type="radio"]')) &amp;&amp; ($(elem).attr('name') !== undefined)) {
    return $('input[name="' + $(elem).attr('name') + '"]:checked').val();
}
</code></pre>

<p>But this is not working if I have similar names in distinct forms, and I don't even know if this is safe to put such a thing on a selector.</p>

<p>My goal is to create a <code>getValue()</code> function that returns value of one element (<code>$(elem).length == 1</code>) without a matter of nature :</p>

<pre><code>var getValue = function(elem) {
    if ($(elem).is('input[type="checkbox"]')) {
        return ($(elem).prop('checked') == true);
    }
    else if (($(elem).is('input[type="radio"]')) &amp;&amp; ($(elem).attr('name') !== undefined)) {
        return $('input[name="' + $(elem).attr('name') + '"]:checked').val();
    }
    else if ($(elem).prop('value') !== undefined) {
        return $(elem).val();
    } else {
        return $(elem).html();
    }
}
</code></pre>

<p>Any suggestion ?</p>
