How to check to make sure a radio button is selected
<p>I have a form that I need to figure out the code on how to make sure a radio button is selected </p>

<p>Here is the form</p>

<pre><code>&lt;body&gt;
    &lt;div id="content"&gt;

        &lt;p&gt;Enter the values below and click "Calculate".&lt;/p&gt;

        &lt;label for="length"&gt;Length:&lt;/label&gt;
        &lt;input type="text" id="length" /&gt;&lt;br /&gt;

        &lt;label for="width"&gt;Width:&lt;/label&gt;
        &lt;input type="text" id="width" /&gt;&lt;br /&gt;

        &lt;label for="answer"&gt;Answer:&lt;/label&gt;
        &lt;input type="text" id="Answer" disabled="disabled" /&gt;&lt;br /&gt;

        &lt;input type="radio" name="Area" value="Area" check="checked"/&gt;Area&lt;br /&gt;
        &lt;input type="radio" name="Parimeter" value="Parimeter"  /&gt;Parimeter&lt;br /&gt;

         &lt;label&gt;&amp;nbsp;&lt;/label&gt;
        &lt;input type="button" id="calculate" value="Calculate" /&gt;&lt;br /&gt;

    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>here is the code</p>

<pre><code>var $ = function (id) {
    return document.getElementById(id);
}

var calculate_click = function () {
    var length = parseFloat( $("length").value );
    var width = parseFloat( $("width").value );

    // $("area").value = "";

    if (isNaN(length) || length &lt;= 0) {
        alert("Length must be a valid number\nand greater than zero.");
    } else if(isNaN(width) || width &lt;= 0) {
        alert("Width must be a valid number\nand greater than zero.");
       }
    } else {
        var area = width * length;
        var perimeter = 2 * width + 2 * length;

        $("area").value = area.toFixed(2);
        $("perimeter").value = perimeter.toFixed(2);
    } 
}

window.onload = function () {
    $("calculate").onclick = calculate_click;
    $("length").focus();

}
</code></pre>
