Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From what I understand, it's because you're doing the calculation in the back-end, yet checking for the sum upon keypress. Try making a callback function to check for the sum.</p> <p>Here's what's happening: </p> <ul> <li>you enter a number</li> <li>AJAX call to the backend</li> <li>you check for the sum</li> <li>AJAX returns and fills the sum field</li> <li>nothing happens</li> <li>you enter another number</li> <li>AJAX call to the backend</li> <li>you check for the sum, find the result from the <strong>previous</strong> AJAX call</li> <li>etc...</li> </ul> <p>That's why it seems like your sum checker is always "one keypress late".</p> <p>UPDATE</p> <p>Upon a quick glance to the backend, it does seem to make some <strike>AJAX</strike> calls and I didn't notice it allows you to set callbacks. This is probably what causes a delay. So this is what I'd do: I'd set a onchange listener to your sum field element and check the sum and paint the number on every change. Something like this:</p> <p><strike>$('.confirmit-as-sum-field').on('change', function(){ var sum = $('.confirmit-as-sum-field').text(); if(parseInt(sum) >100){$('.confirmit-as-sum-field').css('color','red')} else{$('.confirmit-as-sum-field').css('color','black')} });</strike></p> <p>This is how it should work for non-form elements: <a href="http://jsfiddle.net/FUtb9/1/" rel="nofollow">http://jsfiddle.net/FUtb9/1/</a> (try changing its value from your DevTools)</p> <pre><code>$('p.confirmit-as-sum-field').bind('DOMNodeInserted DOMSubtreeModified DOMNodeRemoved', function(event) { var sum = + $('p.confirmit-as-sum-field').text(); if(parseInt(sum) &gt;100){$('.confirmit-as-sum-field').css('color','red')} else{$('p.confirmit-as-sum-field').css('color','black')} alert(sum); }); </code></pre> <p>Here it is with an input field you can use to change the text of your sum field element: <a href="http://jsfiddle.net/FUtb9/2/" rel="nofollow">http://jsfiddle.net/FUtb9/2/</a></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.
 

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