title: How to pass a value into a javascript function within an aspx page onClientClick
body: <p>I want to check the textbox value before postback occurs. I set the <code>onClientClick</code> value to my function but I don't know how to pass the data to check, in this case I want to check the txt1 entered text.</p>
  
  <pre><code>&lt;asp:textbox id="txt1" runat="server /&gt;
  
  &lt;asp:LinkButton ID="LinkButton1"
                  runat="server"
                  Text="Save" 
                  onclick="Save"
                  OnClientClick="javascript:check(WANT TO PUT TEXTBOX VALUE HERE);"
                  /&gt;
  </code></pre>
  
  <p>My javascript:</p>
  
  <pre><code>function check(txt) {
   var pattern = /^[0-9]{1,11}(,[0-9]{0,2})?$/;
   if (!pattern.test(txt)) {
      return false;
   }
   else {
      return true;
   }
  }
  </code></pre>
  
  <p>The issue is that this check function is used along the keypress event of the txt1 so I cant use:</p>
  
  <pre><code>function check(){
      var txt=$('#txt1').val();
  }
  </code></pre>
  
  <p>The whole JS code:</p>
  
  <pre><code>$('#txt1').keypress(function (e) {
      var key = String.fromCharCode(e.which);
      var txt = $(this).val() + key;
      if (check(txt)) {
          // do sth
      } else {
          e.preventDefault();
          // do sth
      }
  });
  </code></pre>
  
  <p>How can I tell the OnclientCLick function to get the txt1 value? </p>
  
  <p>Thank you.</p>