Auto calculation in a JavaScript
<p>I have a script that calculates the values in some  fields in real time at the moment you type the value and it is working fine.
However, if I send the values to a db and then take them back from there and populate the fields from the request from the db the fields are no longer calculated unless they are retyped in the already populated fields.</p>

<p>Any idea how can I do the calculation to fire up at the moment I load the populated form from the db?</p>

<p>This is the Jscript</p>

<pre><code>&lt;script type="text/javascript"&gt;

$(document).ready(function() {
    $('input[id=r],input[id=p]').change(function(e) {
        var total = 0;
        var $row = $(this).parent();
        var rate = $row.find('input[id=r]').val();
        var pack = $row.find('input[id=p]').val();

        total = parseFloat(rate * pack);
        //update the row total
        $row.find('.amount').text(total);

        var total_amount = 0;
        $('.amount').each(function() {
            //Get the value
            var am= $(this).text();
            console.log(am);
if (typeof console == "undefined") {
    this.console = {log: function() {}};
}
            //if it's a number add it to the total
            if (IsNumeric(am)) {
                total_amount += parseFloat(am, 10);
            }
        });
        $('.total_amount').text(total_amount);
    });
});

//isNumeric function Stolen from: 
//http://stackoverflow.com/questions/18082/validate-numbers-in-javascript-isnumeric

function IsNumeric(input) {
    return (input - 0) == input &amp;&amp; input.length &gt; 0;
}
&lt;/script&gt;
</code></pre>

<p>And this is the HTML</p>

<pre><code>        &lt;tr&gt;
            &lt;td&gt;&lt;/td&gt;
            &lt;td&gt;
            &lt;div&gt;
                &lt;input name="a2c" type="text" size="10" value="&lt;? echo "$a2c";?&gt;"&gt;
                &lt;input id="r" class="rate" name="a2q" type="text" maxlength="255" size="5" value="&lt;? echo "$a2q";?&gt;"&gt;
                &lt;input id="p" class="pack" name="a2p" type="text" maxlength="255" size="5" value="&lt;? echo "$a2p";?&gt;"&gt;
                &lt;span class="amount"&gt;&lt;/span&gt;&lt;/div&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;/td&gt;
            &lt;td&gt;
            &lt;div&gt;
                &lt;input name="a3c" type="text" size="10" value="&lt;? echo "$a3c";?&gt;"&gt;
                &lt;input id="r" class="rate" name="a3q" type="text" maxlength="255" size="5" value="&lt;? echo "$a3q";?&gt;"&gt;
                &lt;input id="p" class="pack" name="a3p" type="text" maxlength="255" size="5" value="&lt;? echo "$a3p";?&gt;"&gt;
                &lt;span class="amount"&gt;&lt;/span&gt;&lt;/div&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
</code></pre>
