0

I have a form, in which I accept 3 inputs, among these 3, 2 are accepting values from database, 1 accepts value from user. Upon users input, a sub total is calculated for by addition of 3 values, and over that sub total, a tax is calculated. Now the problem is, the subtotal is calculated correctly, but the tax is calculated only on the first two inputs, the 3rd one is ignored.

Here is the code I tried to calculate all 3 :

function calcGST() {
  var hsncode = $("input[name='hsncode[]']").map(function() {
    return $(this).val();
  }).get();
  console.log("HSNCode " + hsncode);
  var hsnper = $("input[name='hsnper[]']").map(function() {
    return $(this).val();
  }).get();
  console.log("HSNPer " + hsnper);
  var hsnamt = $("input[name='amt[]']").map(function() {
    return $(this).val();
  }).get();
  console.log("HSNAmt " + hsnamt);

  functionToSetAllGstValue(hsnamt, hsncode, hsnper)
  //alert("Called");

  document.getElementById("gtotal1").value = 0.0;
  var cgst_per = document.getElementById("cgst").value; //Central Tax Percent
  var sgst_per = document.getElementById("sgst").value; //State Tax Percent
  var subtot = document.getElementById("subtot").value; //Sub Total

  var sgst_amt = ((sgst_per / 100) * subtot);
  document.getElementById("sgstamt").value = sgst_amt.toFixed(2);
  var cgst_amt = ((cgst_per / 100) * subtot);
  document.getElementById("cgstamt").value = cgst_amt.toFixed(2);
  var gtotal = Number(subtot) + Number(cgst_amt) + Number(sgst_amt);

  //var ramt=gtotal-($subtotal+taxamt+cgst+sgst);
  gtotal = Math.round(gtotal);

  //alert("gtotal "+gtotal);
  document.getElementById("gtotal1").value = gtotal.toFixed(2);

  var ramt = gtotal - (Number(subtot) + Number(cgst_amt) + Number(sgst_amt));
  document.getElementById("ramt").value = ramt.toFixed(2);

  //alert(ramt.toFixed(2));
}

Please guide me.

Rory McCrossan
  • 319,460
  • 37
  • 290
  • 318
  • 1
    Have you tried to step through that code with a [debugger](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems)? – litelite Sep 27 '17 at 14:45
  • Actually I am programming directly on the server, I am not sure how to use a debugger over there. – rushi kulkarni Sep 27 '17 at 14:48
  • 1
    what you mean programming directly on server. – want2learn Sep 27 '17 at 14:57
  • 1
    That is clearly not server-side code. Your web browser have a built-in debugger you can use. – litelite Sep 27 '17 at 14:58
  • What I mean is, I am using phpmyadmin of server on which the application is hosted. Not on local host. – rushi kulkarni Sep 27 '17 at 14:59
  • 1
    That code is _hosted_ on a server. But it still runs in your browser. So you can use your browser's JS debugger. – litelite Sep 27 '17 at 15:00
  • Oh ok. Can u be more specific please? – rushi kulkarni Sep 27 '17 at 15:00
  • 1
    Just right click on you page and inspect the element. This should open the developper tools no matter what browser you are using. From there you should have a debugger section that you can use. And worst case scenario if you _really_ don't understand how to use the debugger you can just blindly alert your variables to have an idea about what's going on. You should really take the time to learn to use these dev tools because they **will** help you in the future no matter if you want to be pro or not. – litelite Sep 27 '17 at 15:04
  • Thanks man, Ill do it. – rushi kulkarni Sep 27 '17 at 15:07

0 Answers0