javascript - JS GST calculation form total is multiplying more then it should -
my total * 10 reason, have made stupid mistake somewhere. working out calculation method form building stuck on last element.
the gst input has no decimal place not overly bothered @ point can added later see should + both elements , output.
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>untitled document</title> </head> <body> <script type="text/javascript"> function updateprice() { // ex-gst price form element var exprice = document.getelementbyid("ex-gst").value; var tprice = document.getelementbyid("gst").value; // gst price gstprice = exprice * 0.1; tprice = gstprice + exprice; // set gst price in form element document.getelementbyid("gst").value = gstprice; document.getelementbyid("inc-gst").value = tprice; } </script> <table border=0 cellspacing=2 cellpadding=2> <tr> <th width="5"> </th> <th width="264"> </th> <th><font size="2" face="geneva, arial, helvetica, sans-serif">attendees</font></th> </tr> <tr> <td align=center> </td> <td align=right>calculate</td> <td align=right> <input id="ex-gst" name="ex-gst" value="0.00" size=7 maxlength=10 onchange="updateprice()"></td> </tr> <tr> <td align=center> </td> <td align=right> 12.5% g.s.t </td> <td align=right> <input type=text id="gst" name="gst" size=7 maxlength=10 value="0.00" onchange="updateprice()"></td> </tr> <tr> <td align=center> </td> <td align=right>total payable</td> <td align=right> $ <input name="inc-gst" id="inc-gst" type="text" value="0.00" size=7 maxlength=10 onchange="updateprice(this.form)"> </td> </tr> </table> </body> </html>
got working, had make slight edits
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>untitled document</title> </head> <body> <script type="text/javascript"> function updateprice() { // ex-gst price form element var exprice = document.getelementbyid("ex-gst").value; var gstprice = document.getelementbyid("gst").value; // gst price gstprice = exprice * 0.1; var tprice = parseint(gstprice) + parseint(exprice); // set gst price in form element document.getelementbyid("gst").value = gstprice; document.getelementbyid("inc-gst").value = tprice; } </script> <table border=0 cellspacing=2 cellpadding=2> <tr> <th width="5"> </th> <th width="264"> </th> <th><font size="2" face="geneva, arial, helvetica, sans-serif">attendees</font></th> </tr> <tr> <td align=center> </td> <td align=right>calculate</td> <td align=right> <input id="ex-gst" name="ex-gst" value="0.00" size=7 maxlength=10 onchange="updateprice()"></td> </tr> <tr> <td align=center> </td> <td align=right> 12.5% g.s.t </td> <td align=right> <input type=text id="gst" name="gst" size=7 maxlength=10 value="0.00" onchange="updateprice()"></td> </tr> <tr> <td align=center> </td> <td align=right>total payable</td> <td align=right> $ <input name="inc-gst" id="inc-gst" type="text" value="0.00" size=7 maxlength=10 onchange="updateprice(this.form)"> </td> </tr> </table> </body> </html>
Comments
Post a Comment