title: Using javascript from an ASP.NET textbox
body: <p>I am currently making an ASP.Net page as a part of a project;
  While making the main registration/Login page validators (Labels that change their visibility on javascript and trigger on the OnChange event of their recpective textboxes), I faced a problem. Allthough it worked perfectly fine in our computer labs (which means the javascript code itself is probably correct), the validators do not work at all - regardless of the input.
  Any idea why would it possibly happen?</p>
  
  <p>Thank you!</p>
  
  <p>Javascript: </p>
  
  <pre><code>function isUserValid() {
      var UserLength = document.getElementById("UserTB").value.length;
      var ValidatorLabel = document.getElementById("ValidateUser");
      if (UserLength &lt; 6 || UserLength &gt; 15) {
          ValidatorLabel.style.display = 'inline';
          return false;
          }
      else {
          ValidatorLabel.style.display = 'none';
          return true;
      }  
      }
  function isPassValid() {
          var PassLength = document.getElementById("PasswordTB").value.length;
          var ValidatorLabel = document.getElementById("ValidatePassword");
          if (PassLength &lt; 6 || PassLength &gt; 15) {
              ValidatorLabel.style.display = 'inline';
              return false;
          }
          else {
              ValidatorLabel.style.display = 'none';
              return true;
          }
      }
  function isConfirmValid() {
          var Password = document.getElementById("PasswordTB").value;
          var Me = document.getElementById("ConfirmTB").value;
          var ValidatorLabel = document.getElementById("ValidateConfirm");
          if (Password == Me) {
              ValidatorLabel.style.display = 'none';
              return true;
          }
          else {
              ValidatorLabel.style.display = 'inline';
              return false;
          }
      }
  function isEmailValid() {
          var str = document.getElementById("EmailTB").value;
          var lastAtPos = str.lastIndexOf('@');
          var lastDotPos = str.lastIndexOf('.');
          var isFine = (lastAtPos &lt; lastDotPos &amp;&amp; lastAtPos &gt; 0 &amp;&amp; str.indexOf('@@') == -1 &amp;&amp; lastDotPos &gt; 2 &amp;&amp; (str.length - lastDotPos) &gt; 2);
          var ValidationLabel=document.getElementById("ValidateEmail");
          if(isFine)
          {
              ValidationLabel.style.display='none';
              return true;
          }
          else
          {
              ValidationLabel.style.display='inline';
              return false;
          }
      }
  </code></pre>
  
  <p>In the ASP:</p>
  
  <pre><code>&lt;script src="Validators.js" type="text/javascript"&gt;&lt;/script&gt;
  ....
  </code></pre>
  
  <p>ASP "validators":</p>
  
  <pre><code>Username:&lt;br /&gt;
      &lt;asp:TextBox ID="UserTB" runat="server" OnChange="return isUserValid();" AutoPostBack="false"&gt;&lt;/asp:TextBox&gt;
      &lt;asp:Label ID="ValidateUser" runat="server" ForeColor="Red"
          Text="Username must be 6-15 characters in length, and contain no special characters." CssClass="Validators"&gt;&lt;/asp:Label&gt;
      &lt;br /&gt;&lt;br /&gt;
      Password:&lt;br /&gt;
      &lt;asp:TextBox ID="PasswordTB" runat="server" OnChange="return isPassValid();" AutoPostBack="false"&gt;&lt;/asp:TextBox&gt;
      &lt;asp:Label ID="ValidatePassword" runat="server" ForeColor="Red"
          Text="Password must be 6-15 characters in length, and contain no special characters." CssClass="Validators"&gt;&lt;/asp:Label&gt;
      &lt;br /&gt;&lt;br /&gt;
      Confirm password:&lt;br /&gt;
      &lt;asp:TextBox ID="ConfirmTB" runat="server" OnChange="return isConfirmValid();" AutoPostBack="false"&gt;&lt;/asp:TextBox&gt;
      &lt;asp:Label ID="ValidateConfirm" runat="server" ForeColor="Red"
          Text="This field must match the password field." CssClass="Validators"&gt;&lt;/asp:Label&gt;
      &lt;br /&gt;&lt;br /&gt;
      Email:&lt;br /&gt;
      &lt;asp:TextBox ID="EmailTB" runat="server" OnChange="return isEmailValid();" AutoPostBack="false"&gt;&lt;/asp:TextBox&gt;
      &lt;asp:Label ID="ValidateEmail" runat="server" ForeColor="Red" Text="Invalid Email." CssClass="Validators"&gt;&lt;/asp:Label&gt;
  </code></pre>