Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to overwrite this code in jquery
    primarykey
    data
    text
    <p>Below is the code I have where it is suppose to display the number within the textbox when the "Add" button is clicked on <code>$('#mainNumberAnswerTxt').val(numberAnswer);</code>. But I also have a line of code where it triggers the function for when a (btn 'button') is clicked on.</p> <pre><code> function addwindow(numberAnswer, gridValues, btn) { $('#mainNumberAnswerTxt').val(numberAnswer); $('#btn'+gridValues).trigger('click'); } </code></pre> <p>Because of the trigger it triggers this function <code>$('.gridBtns').on('click', function()</code>. In this function is this line of code</p> <pre><code>$('.answertxt', context).val(context.find('.answerBtnsOn').length &gt; 0 ? context.find('.answerBtnsOn').length : '');, </code></pre> <p>This line of code checks for how many buttons were turned on when the gridBtn is clicked and displays the number in the textbox. But the line of code above is overwriting the <code>$('#mainNumberAnswerTxt').val(numberAnswer);</code> in the addwindow() function. </p> <p>EXAMPLE:</p> <p>If there were 2 '#btns' which were turned on but then I click on the "Add" button to add the number displayed under the "Number of Answers" column (lets say this number is 1), then it should display number 1 in the textbox by this code taking affect <code>$('#mainNumberAnswerTxt').val(numberAnswer);</code>, but instead it is displaying number 2, because this code is taking affect: <code>$('.answertxt', context).val(context.find('.answerBtnsOn').length &gt; 0 ? context.find('.answerBtnsOn').length : '');</code> </p> <p>How can I get number 1 to be displayed and not number 2 to be displayed in the example above</p> <p>Below is html code of textbox:</p> <pre><code>&lt;input type="text" name="numberAnswer" class="numberAnswerTxt answertxt" id="mainNumberAnswerTxt" readonly="readonly" onChange="getButtons()" &gt; </code></pre> <p>UPDATE:</p> <p>Here is a <a href="http://helios.hud.ac.uk/u0867587/Mobile_app/Text14.php" rel="nofollow">demo</a> of the application. Please follow the steps below:</p> <ul> <li>Step 1: When you open up the demo, click on the "Open grid" link and select button "7". This will display a textbox and 7 letter buttons underneath.</li> <li>Step 2: Select 4 letter buttons underneath of you choice. You will see when you turn on a letter button the textbox above counts it.</li> <li>Step 3: Now on left hand side you will see a green plus button, click on it and it opens up a modal window.</li> <li>Step 4: In modal window there is a search bar, type in "AAA" and submit search, you will see a bunch of rows appear.</li> <li>Step 5: In the first row, you see under "Number of Answer" colum that it contains the number 1, click on the "Add" button within this row, the modal window will close but there is problem which you can read below.</li> </ul> <p>Problem:</p> <p>In the "Number of Answers" textbox, it should display the number 1, but it doesn't. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload