title: Undesired effects when calculating 2 amounts with jQuery
body: <p>I am not getting the desired output with this code. Everything seems to be working except if for example you enter anything between 100 - 199. It gives a negative number in the other box, when I would like it to just split the balance into both boxes. You can see a working example here: <a href="http://jsfiddle.net/bFJq2/" rel="nofollow">http://jsfiddle.net/bFJq2/</a> ( enter in 100 to see what I mean )</p>
  
  <p>Not sure if there is something I am doing wrong, I feel like it is treating the number as a decimal or something. Any help is greatly appreciated.</p>
  
  <p>Here is the JS:</p>
  
  <pre><code>// make sure both inputs are equal to balance
  $('input[id*="amount"]').on("blur", function() {
      var balance     = $('#balance').val()
         ,thisAmount  = $(this)
         ,otherAmount = $('input[id*="amount"]').not(this);
  
      // check if value is less than balance
      if(thisAmount.val() &lt; balance &amp;&amp; thisAmount.val() + otherAmount.val() &lt;= balance){
          // if so populate other input with remaining amount
          otherAmount.val(balance - thisAmount.val());
      }
  
      // check to make sure amount is not greater than balance
      if((thisAmount.val() + otherAmount.val()) &gt; balance){
          $('input[id*="amount"]').not(this).val(function(){
              // if value is greater than balance, just split balance into both amounts
              if(thisAmount.val() &gt; balance){
                  thisAmount.val(balance/2);
                  return balance/2;
              }
          });
      }
  });
  </code></pre>