title: jquery - why code always takes old value of textbox?
body: <p>I've a form with two textboxes for API Key and for stock ticker. Please find below the code.</p>
  
  <pre><code>&lt;h1&gt;Stock&lt;/h1&gt;
  &lt;form id="frmGetComp"&gt;
      &lt;p&gt;API Key: &lt;input type="text" id="txtAPI" value="" /&gt;&lt;/p&gt;
      &lt;p&gt;Stock: &lt;input type="text" id="txtStock" value="" /&gt;&lt;/p&gt;
      &lt;p&gt;&lt;button id="btnCall"&gt;Call&lt;/button&gt;&lt;/p&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And below is the jquery code:</p>
  
  <pre><code>$(document).ready(function () {                                     
              var stockId='';
  
              $("#txtStock").blur(function () {
                  stockId= $(this).val();
                  console.log(stockId);
              });
  
              $('#btnCall').click(function () {
                  var apiKey = $('#txtAPI').val();
  
                  stockId= $("#txtStock").val();
                  console.log(':::call clicked:::', stockId);
  
                  &lt;assigning apikey statement&gt; = apiKey;
                  &lt;stockId is passed in api call to fetch stock information&gt;
  
                  $('#frmGetComp').submit(false);
                  $('#frmGetComp').reset = true;
                  stockId= '';
                  $('#txtStock').val('');
  
              });
          });
  </code></pre>
  
  <p>Now in this form when I enter information first time it retruns correct data. When I change the value of stock and click call button, every time it returns the stock information of first stock. It never takes new value entered in stock textbox.</p>
  
  <p><strong>How do I get new value of stock textbox and get the information of that stock when call button is clicked ???</strong></p>