title: Trying to call a javascript function with variable from ASP.NET
body: <p>I have a simple text field that looks like this.</p>
  
  <pre><code>&lt;asp:TextBox ID="txtMyTextBox" runat="server" onblur="checkMyText()"  &gt;&lt;/asp:TextBox&gt;
  </code></pre>
  
  <p>At the top of my page, I have this little bit of JS</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function checkMyText() {
          var args = document.getElementById('&lt;% =txtMyTextBox.ClientId %&gt;').value;
          alert(args);
          }
  &lt;/script&gt;
  </code></pre>
  
  <p><em>This works fine</em>. When I try to do this.</p>
  
  <pre><code> &lt;asp:TextBox ID="txtMyTextBox" runat="server" onblur="checkMyText("txtMyTextBox")"  &gt;&lt;/asp:TextBox&gt;
  </code></pre>
  
  <p>.
  .
  .</p>
  
  <pre><code> function checkMyText(ElementID) {
                  var args =  document.getElementById('&lt;% =ElementID.ClientId %&gt;').value;
                  alert(args)
                  }
  </code></pre>
  
  <p>It fails. </p>
  
  <p>I am entirely new to javascript, so I am not sure how it handles passing variables or treating them inside strings. The idea is if I add an: ID="txtMyOtherTextBox" I only need to call onblur="checkMyText("txtMyOtherTextBox")" for that button. How do I javascript strings?</p>