1

I am trying to call 'A' function from 'B' function in JQuery. The function 'A' is defined before the 'B' function. But whenever I try to run the 'B' functions script, I am getting a reference error : 'A' function not defined.

Here is the code of both 'A' as well as 'B' function.

Here

'A'= calcGST(); & 'B'=SetDefault();

I have also attached the console's error below.

function SetDefault(a, Text)
{

   var z = Number(1); 
   console.log("count"+$("#icount").val());
   console.log("count "+$("#icount").val());
   var subtot=0;var TaxAmt=0;
   for(z=1; z<=$("#icount").val();z++)
   {

       var inv = $("#invqty"+z).val();           
       if(inv==null)
       {
      inv=0;
   }             

       var rt= $("#rate"+z).val();

       if(rt==null)
       {
          rt=0;
       }

           var at = inv*rt;

           $("#amt"+z).val(at);
           subtot=at+subtot;

   }
   console.log(subtot);
   document.getElementById("subtot").value=subtot;
   calcGST();


}

Here is my calcGST()-

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
  console.log("cgst_per"+cgst_per);
  var sgst_per = document.getElementById("sgst").value;//State Tax Percent

  var subtot = document.getElementById("subtot").value;//Sub Total
  console.log("subtot"+subtot);
   var sgst_amt=((sgst_per/100)*subtot); 
   console.log("sgst_amt"+ sgst_amt);
  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));

}

Here is my console error :

ReferenceError: calcGST is not defined[Learn More]  new_tax_invoice.php:853:4
SetDefault http://vijayneetigroup.com/ERP/rugwed/pages/new_tax_invoice.php:853:4
onchange http://vijayneetigroup.com/ERP/rugwed/pages/new_tax_invoice.php:1:1

Please guide me.

Thanks in advance.

23
  • In which files you have defined these function? and In what scope? Commented Sep 28, 2017 at 8:03
  • In the same file sir. Both the functions are in same file. Commented Sep 28, 2017 at 8:08
  • Check if there is an error in the calcGST function. is your setAllToGstValue function defined? Commented Sep 28, 2017 at 8:10
  • Yes, I have defined setAllToGstValue function defined. But I did not post it because the question would have been pretty lengthy. Commented Sep 28, 2017 at 8:12
  • Are these two functions found in one script tag?. You might put this functions in different parts of your PHP file Whereas one part rendered in the page and another may not. Commented Sep 28, 2017 at 8:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.