Onchange client script for calculation

SAM321
Tera Contributor

Screenshot (188).pngScreenshot (189).png

Hi all , so this is my script for calculating values in field on changing value in GST field....

How can i modify this script...  Initially CGST  and SGST values '320'wil l be auto calculated at that time IGST should show only '0'...when i manually change CGST and SGST to '0' only at that time IGST should show '640'...

can i get script for it

16 REPLIES 16

lp6
Tera Guru

that is expected right when you give same value then it will give the sum other wise it will be 0, If you don't want 0 then replace with space in code

Ravi Gaurav
Giga Sage
Giga Sage

var gst = parseFloat(document.getElementById("gst").value);
var cgst = 0;
var sgst = 0;
var igst = 0;

if (gst !== 0) {
cgst = sgst = gst / 2;
}

if (cgst === 0 && sgst === 0) {
igst = 640;
} else {
igst = 0;
}

document.getElementById("cgst").value = cgst.toFixed(2);
document.getElementById("sgst").value = sgst.toFixed(2);
document.getElementById("igst").value = igst.toFixed(2);

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/