javascript validation
<p>I have two radio buttons. Each one has one associated text box. If I click one radio button and then submit an alert box should be shown if the associated text box is empty. How can I achieve this?  </p>

<pre><code>&lt;form action="#" name="form1" id="form1" method="post" onsubmit="return check_workorder()"&gt;
     &lt;input type="radio" name="click" id="click1" checked="checked" value="date"/&gt;
            &lt;strong&gt;Start Date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
              &lt;input type="text" id="my_date_field" name="my_date_field" class="datepicker" style="width:80px;"/&gt;
              &lt;/strong&gt;
            &lt;script language="JavaScript" type="text/javascript"&gt;
            new Control.DatePicker('my_date_field', { icon: 'images/calendar.png' });
            &lt;/script&gt;
            &lt;/br&gt;&lt;br /&gt;
            &lt;input type="radio" name="click" id="click2" value="order" /&gt;
            &lt;strong&gt;Work order no
            &lt;input type="text" name="workno" id="workno" style="width:100px;"/&gt;
            &lt;/strong&gt;&lt;span class="submit"&gt;
            &lt;input type="submit" name="submit" value="submit" onclick="return check_workorder()"/&gt;
</code></pre>

<p>the javascript is</p>

<pre><code>function check_workorder() {
    if (document.forms.form1.elements.click.value == "date") {
        var dat = (form1.my_date_field.value);
        if (dat == "") {
            alert("please select date");
            return false;
        }
    } else if (document.forms.form1.elements.click.value == "order") {
        var wor = (form1.workno.value);
        if (wor == "") {
            alert("please enter work order no");
            return false;
        }
    }
}
</code></pre>
