Note that there are some explanatory texts on larger screens.

plurals
  1. POSum a number on key type javascript
    primarykey
    data
    text
    <p>I have an auto update sum form which is runs perfectly with 3 inputs. But I need one more input to be calculated. I tried to add a field and tried to mimic the script but have no luck. Please help.</p> <pre><code>function formatDollar(num) { var p = num.toFixed(2).split("."); return "" + p[0].split("").reverse().reduce(function(acc, num, i, orig) { return num + (i &amp;&amp; !(i % 3) ? "," : "") + acc; }, ""); } //auto sum function calculateDiscount() { var cost = document.getElementById('insr_total1').value.replace(/[^0-9]+/i,""); cost = cost.replace(/[^0-9]+/i,""); var discount = document.getElementById('insr_discount').value; //do the math var net = cost-discount; //update document.getElementById('insr_discount2').innerHTML = formatDollar(cost*(discount/100)); document.getElementById('insr_total3').value = formatDollar(cost-cost*(discount/100)); } </code></pre> <p>And this is the html I use with:</p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;td align="left" valign="top"&gt;Cost1&lt;/td&gt; &lt;td align="left" valign="top"&gt;&lt;input type="text" name="insr_total1" id="insr_total1" size="17" maxlength="15" onKeyup="calculateDiscount(); return false;" /&gt; USD&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left" valign="top"&gt;Discount&lt;/td&gt; &lt;td align="left" valign="top"&gt;&lt;input type="text" name="insr_discount" id="insr_discount" size="4" maxlength="3" onkeyup="calculateDiscount(); return false;" /&gt; % (&lt;span id="insr_discount2" style="color:green; font-size: 13px;"&gt;&lt;/span&gt; USD)&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left" valign="top"&gt;Cost 2&lt;/td&gt; &lt;td align="left" valign="top"&gt;&lt;input type="text" name="insr_total2" id="insr_total2" size="17" maxlength="15" /&gt; USD&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left" valign="top"&gt;Overall&lt;/td&gt; &lt;td align="left" valign="top"&gt;&lt;input type="text" name="insr_total3" id="insr_total3" size="17" readonly maxlength="15" /&gt; USD&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>Well, I need "insr_total2" to subtract from insr_total3. It always gets error no matter I tried. Appreciated for all reply.</p>
    singulars
    1. This table or related slice is empty.
    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