Microsoft JScript runtime error: Object required
<p>I wrote a simple javascript function for validating to fields in a aspx page</p>

<pre><code>function validate()

{
 if (document.getElementById("&lt;%=tbName.ClientID%&gt;").value=="")
  {
             alert("Name Feild can not be blank");
             document.getElementById("&lt;%=tbName.ClientID%&gt;").focus();
             return false;
  }
  if (document.getElementById("&lt;%=ddlBranch.ClientID%&gt;").value=="SelectBranch")
  {
             alert("Branch Should Be Selected");
             document.getElementById("&lt;%=ddlBranch.ClientID%&gt;").focus();
             return false;
  }

}
</code></pre>

<p>Everything worked fine.
Later I linked it to aspx page like a external js file.</p>

<p>head runat="server"></p>

<p>script src="validation.js" type="text/javascript"> </p>

<p>/script></p>

<pre><code>&lt;title&gt;Validations&lt;/title&gt;
</code></pre>

<p>/head></p>

<p></p>

<pre><code>&lt;form id="form" runat="server"&gt;



&lt;asp:Label ID="lblName" runat="server" Text="Nmae: "&gt;/asp:Label&gt;
&lt;asp:TextBox ID="tbName" runat="server" Width="130px"&gt;/asp:TextBox&gt;

&lt;asp:Label ID="lblBranch" runat="server" Text="Branch:"&gt;/asp:Label&gt;
    &lt;asp:DropDownList ID="ddlBranch" runat="server" Width="107px"&gt;
        &lt;asp:ListItem&gt;CSE&lt;/asp:ListItem&gt;
        &lt;asp:ListItem&gt;ECE&lt;/asp:ListItem&gt;
        &lt;asp:ListItem&gt;CIVIL&lt;/asp:ListItem&gt;
        &lt;asp:ListItem&gt;MECH&lt;/asp:ListItem&gt;
        &lt;asp:ListItem Selected="True" Value="SelectBranch"&gt;SelectBranch&lt;/asp:ListItem&gt;
    &lt;/asp:DropDownList&gt;    
&lt;asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="return validate(&lt;%=tbName.ClientID%&gt;, &lt;%=ddlBranch.ClientID%&gt;)" /&gt;

&lt;/form&gt; 
</code></pre>

<p>
and</p>

<p>In aspx.cs page</p>

<p>protected void Page_Load(object sender, EventArgs e)</p>

<pre><code>{
    Page.RegisterClientScriptBlock("MyScript", "&lt;SCRIPT Language='JavaScript' src='validation.js'&gt;&lt;/SCRIPT&gt;"); 
    btnSubmit.Attributes.Add("onclick", "return validate()");

}
</code></pre>

<p>Now its giving error "Microsoft JScript runtime error: Object required".</p>

<p>I'm unable to know where I went wrong.</p>
