title: How to get the client id of a textbox which is inside a gridview from Javascript
body: <p>I've been having this problem my whole day and I have seen almost every post on every forum/page there is and I have not found the solution to my problem. I will try to be as brief and precise as possible in my explanation.</p>
  <p>What I want is simple, I want to dynamically copy entered numbers in <code>txtBox1</code> into <code>txtBox2</code>. Both of these txtBoxes are inside a Table which is inside a <code>TemplateField</code> which is inside a <code>GridView</code>. The <code>txtBox1</code> calls a JavaScript <code>numericOnly</code> function using the <code>onkeydown</code> event. When the user inputs a number the <code>numericOnly</code> function fires and just before the return true clause I call another JavaScript function which its supposed to do the dynamic copy from numbers entered in <code>txtBox1</code> into <code>txtBox2</code>.</p>
  <p>The problem here is that whenever I try to use</p>
  <pre><code>document.getElementById('&lt;%= txtDeathPremiumDifference.ClientID %&gt;');
  </code></pre>
  <p>the page throws this error:</p>
  <blockquote>
  <p>&quot;The name txtDeathPremiumDifference does not exist in the current context&quot;</p>
  </blockquote>
  <p>I must insist, I have tried EVERYTHING I've fount on internet even this:</p>
  <pre><code>document.getElementById(''&lt;%# ((GridViewRow)Container')
          .FindControl(&quot;txtDeathPremiumDifference&quot;).ClientID %&gt;'')
          .value=&quot;Hi&quot;;
  </code></pre>
  <p>but nothing has worked.</p>
  <p>Bottom line I need to be able to access the value of my textboxes so I can modify whatever they are holding.</p>
  <p>This is the <code>&quot;txtBox1&quot;</code> its not actually called like that but you get the idea:</p>
  <pre><code>TextBox ID=&quot;txtDeathBankPremium&quot; runat=&quot;server&quot; CssClass=&quot;TexboxInput&quot;
       MaxLength=&quot;17&quot; Width=&quot;122px&quot; onkeydown=&quot;return isNumericKey(event);&quot;
  </code></pre>
  <p>and here's the JS functions:</p>
  <pre><code>function isNumericKey(e)
          {
              var charInp = window.event.keyCode; 
              if (charInp &gt; 31 &amp;&amp; (charInp &lt; 48 || charInp &gt; 57)) 
              {
                  return false;
              }
              ComputePremiumDifference(charInp);
              return true;
          }
          
          function ComputePremiumDifference(input) {
              document.getElementById('&lt;%= txtDeathPremiumDifference.ClientID %&gt;')
                      .value=&quot;Hi&quot;;
          }
  </code></pre>