How do i validate a field based on the input of another field
<p>i have 2 fields and i need to make one of the fields a required fields only if the other field has content of "NO" value in it. So i have researched online and this is what i ended up having.  The only question i have and need help with this is  the first part of the code where it calls this: .getElementByID.  How can i construct that or if you could shed some lights on will be great.  thanks.</p>

<pre><code>&lt;script&gt;
        function Validate(source, args) {
                if (document.getElementById('&lt;%= TextBox1.ClientID %&gt;').value.toUpperCase() == "NO" &amp;&amp;
                document.getElementById('&lt;%= TextBox2.ClientID %&gt;').value.length == 0)
                        args.IsValid = false;
                else
                        args.IsValid = true;
        }
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
        &lt;form id="form1" runat="server"&gt;
        &lt;asp:TextBox ID="TextBox1" runat="server"&gt;&lt;/asp:TextBox&gt;
        &lt;asp:TextBox ID="TextBox2" runat="server"&gt;&lt;/asp:TextBox&gt;
        &lt;asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="TextBox2 Should Be Filled"
                Display="Dynamic" ClientValidationFunction="Validate" OnServerValidate="CustomValidator1_ServerValidate"&gt;&lt;/asp:CustomValidator&gt;
        &lt;asp:Button ID="Button1" runat="server" Text="Button" /&gt;
        &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

protected void Page_Load(object sender, EventArgs e)
        {
                if (!Page.IsPostBack)
                {
                        Page.Validate();
                        if (!Page.IsValid)
                                Response.Write("TextBox2 should be filled");

                }
        }

        protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {
                args.IsValid = !(this.TextBox1.Text.Equals("NO", StringComparison.CurrentCultureIgnoreCase) &amp;&amp; this.TextBox2.Text.Length == 0);
</code></pre>
