dynamic inputs with keyup()
<p>I got a problem with a script with 3 inputs</p>

<p>While the user is typing a script should calculate some results.. It works almost as it should exept when the <code>Sale</code> input has a value and the user edit the <code>Avance</code> input, the script doesn't return the results?</p>

<p><a href="http://jsfiddle.net/pxaYf/" rel="nofollow">http://jsfiddle.net/pxaYf/</a></p>

<pre><code>&lt;div id="tst" style="border:1px solid black; background:white; width:100px; height:100px"&gt;&lt;/div&gt;

Cost = &lt;input id="inp_cost" type="text" /&gt;&lt;br&gt;
Avance = &lt;input id="inp_avance" type="text" /&gt;&lt;br&gt;
Sale = &lt;input id="inp_sale" type="text" /&gt;&lt;br&gt;

$(function(){
    var calc = function(){
        var Calc = new Calc_avance();
        Calc.cost = $('#inp_cost').val();
        Calc.avance = $('#inp_avance').val();
        Calc.sale = $('#inp_sale').val();
        Calc.calc();

        $('#tst').html('&lt;div&gt;cost = '+Calc.cost+'&lt;/div&gt;&lt;div&gt;avance = '+Calc.avance+'&lt;/div&gt;&lt;div&gt;sale = '+Calc.sale+'&lt;/div&gt;');

        return Calc;
    };

    var calc_cost = function(){
        var Calc = calc();
    };

    $('#inp_cost').change(calc_cost)
        .keyup(calc_cost);

    var calc_avance = function(){
        var Calc = calc();
    };

    $('#inp_avance').change(calc_avance)
        .keyup(calc_avance);

    var calc_sale = function(){
        var Calc = calc();
    };

    $('#inp_sale').change(calc_sale)
        .keyup(calc_sale);
});

function Calc_avance(){
    this.cost = 0;
    this.avance = 0;
    this.sale = 0;

    this.calc = function(){
        this.cost = parseFloat(this.cost.replace(',', '.'));
        this.avance = parseFloat(this.avance.replace(',', '.'));
        this.sale = parseFloat(this.sale.replace(',', '.'));

        if(!isNumber(this.cost)){
            this.cost = 0;
        }

        if(!isNumber(this.avance)){
            this.avance = 0;
        }

        if(!isNumber(this.sale)){
            this.sale = 0;
        }

        if(this.cost){
            if(this.sale){
                this.avance = (this.sale - this.cost) / this.sale * 100;
            }

            if(this.avance){
                this.sale = this.cost / (100 - this.avance) * 100;
            }
        }
        else{
            this.avance = 0;
        }

        if(this.avance &lt; 0){
            this.avance = 0;
        }
    };
}

function isNumber(n){
    return !isNaN(parseFloat(n)) &amp;&amp; isFinite(n);
}
</code></pre>
