title: calculate division of fields dynamically using Jquery or Javascript
body: <p>I'm "trying" to figure out how to calculate a division between to fields dynamically to display in another field, the thing is, all examples I've seen are sums, and those used something like this: <code>$('#field').each(function(){....});</code>.</p>
  
  <p>I can't do that because there's no way of know which is the dividend and which is the divisor. I tried using "bind", to try to attach the function to the field. It didn't work. </p>
  
  <p>Also tried putting "onChange="CalcularSaldo()" on the input field; no luck, but mainly because i'm pretty sure my function is wrong:</p>
  
  <pre><code>  &lt;script type="text/javascript"&gt;
   $(document).ready(function() {
    function calcularSaldo() {
    var costo = document.getElementById("costo_ad").value;
    var vida = document.getElementById("vida_util").value; 
    document.getElementById("saldo_dep").value = costo / vida;
    }
    });&lt;/script&gt;
  </code></pre>
  
  <p>Inputs:</p>
  
  <pre><code>  &lt;label for="costo_ad"&gt;Costo de Adquisicion&lt;/label&gt;
    &lt;input name="costo_ad" type="text" id="costo_ad" class="round default-width-input" /&gt;
  
   &lt;label for="vida_util"&gt;Vida Util&lt;/label&gt;
   &lt;input name="vida_util" type="text" id="vida_util" class="round default-width-input" /&gt;
  
   &lt;label for="saldo_dep"&gt;Saldo a Depreciar&lt;/label&gt;
   &lt;input name="saldo_dep" type="text" id="saldo_dep" class="round default-width-input" disabled /&gt;
  </code></pre>
  
  <p>and the function should be something like this:</p>
  
  <pre><code>saldo_dep = costo_ad / vida_util
  </code></pre>