Object Require in JavaScript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krisssgopi
    New Member
    • Apr 2010
    • 39

    Object Require in JavaScript

    Hi Team,

    Am using java script in asp.net for input validation. When i run the below program it was throwing an exception Object expected. Please advice me where it was going wrong. Thanks in advance. i have attached the full code for your reference.
    Code:
    <script language="javascript" type="text/javascript">
    function check()
    {
    if(document.getElementById('TextBox1').value=="")
    alert("enter username");
    }
    </script>
    <td class='list'><asp:TextBox  CssClass="text" ID="TextBox1" runat="server" ></asp:TextBox></td>
    Query.txt
  • Christopher Nigro
    New Member
    • Jul 2010
    • 53

    #2
    Look at the rendered HTML by viewing the source of the page in the browser. Locate your textbox. I am guessing that the ID is not 'TextBox1', correct? If it isn't, you can do one of two things:

    1. Use the ID that is generated by the .NET runtime. This isn't the best approach: if the structure of your page changes over time, the ID may also change.

    2. Use this in your javascript code:
    Code:
    if(document.getElementById('<%=TextBox1.ClientID%>').value=="")

    Comment

    • krisssgopi
      New Member
      • Apr 2010
      • 39

      #3
      Originally posted by Christopher Nigro
      Look at the rendered HTML by viewing the source of the page in the browser. Locate your textbox. I am guessing that the ID is not 'TextBox1', correct? If it isn't, you can do one of two things:

      1. Use the ID that is generated by the .NET runtime. This isn't the best approach: if the structure of your page changes over time, the ID may also change.

      2. Use this in your javascript code:
      Code:
      if(document.getElementById('<%=TextBox1.ClientID%>').value=="")
      Hi Buddy,

      i have tried as you mentioned. But still it was throwing the same error. Since am using master page the child page which inherits the master page. It was working fine in normal asp page. The issue was, when am using master page content place holder. Please help me.

      Comment

      • Christopher Nigro
        New Member
        • Jul 2010
        • 53

        #4
        Please show what you tried. I ran a simple test and it worked for me.

        Comment

        Working...