title: number in textbox needs working
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/11491177/code-is-taking-effect-when-it-shouldnt-be">Code is taking effect when it shouldn&#39;t be</a>  </p>
  </blockquote>
  
  
  
  <p>I have a function where if the user clicks on a button, it will display a value in the textbox and it will perform a trigger to another function after a '#btn' button is clicked:</p>
  
  <pre><code>function addwindow(numberAnswer, gridValues, btn) { 
      $('#mainNumberAnswerTxt').val(numberAnswer).data('data-ignore',true);
      $('#btn'+gridValues).trigger('click');       
   }
  </code></pre>
  
  <p>Now what I want to do is that:</p>
  
  <ol>
  <li><p>if the user clicked on the "Add" button, then display the number from the "Number of Answers" column into the textbox or in other words perform this from the <code>addwindow()</code> function:</p>
  
  <p><code>$('#mainNumberAnswerTxt').val(numberAnswer).data('data-ignore',true);</code></p></li>
  <li><p>If the user has clicked on a <code>#btn+gridValues</code> button, then display the number in the textbox of the number of buttons which are currently turned on or in other words perform this code:</p>
  
  <p><code>if ($('#mainNumberAnswerTxt').data('data-ignore') != true) {
      $('.answertxt', context).val(context.find('.answerBtnsOn').length &gt; 0 ? context.find('.answerBtnsOn').length : 0);
  }</code></p></li>
  </ol>
  
  <p>The problem is that step 1 works fine, it does display the number from the "Number of Answers" column in the textbox after the user has clicked on the "Add" button.</p>
  
  <p>The problem is step 2, it is not displaying the correct number on how many buttons are currently turned on after the user has clicked on the <code>#btn+gridValues</code> button.It just doesn't change the number in the textbox.</p>
  
  <p>Does anyone know why this is happening and how thi can be fixed?</p>
  
  <p>DEMO:</p>
  
  <p>Here is a <a href="http://helios.hud.ac.uk/u0867587/Mobile_app/Text14.php" rel="nofollow noreferrer">demo</a> of the application. Please follow the steps below:</p>
  
  <p>Step 1: On left hand side you will see a green plus button, click on it and it opens up a modal window.
  Step 2: In modal window there is a search bar, type in "AAA" and submit search, you will see a bunch of rows appear.
  Step 3: In the last row, you see under "Number of Answer" colum that it contains the number 4, click on the "Add" button within this row, the modal window will close.</p>
  
  <p>You will see that the textbox displays the number 4 in the textbox which is fine as that was the number within the row under the "Number of Answers" column when you added the row.</p>
  
  <p>But below is the problem:</p>
  
  <p>Step 4: If you click on the "Open Grid" link and select button 3, you will see the letter buttons below change to A-C with only letter "B" turned on.</p>
  
  <p>In the textbox it should display number 1 as only 1 button is turned on, but it doesn't display this number and that is the problem I am having.</p>
  
  <p>How can this problem be fixed?</p>