JavaScript Program to Calculate the Sum Total

In this scripting program, you will learn how to calculate the sum total of the 5 subjects. Each individually entered by the users and finally, the user will calculate the total by clicking on the total button.




  function calculateMarks(math, science, english, nepali, social) {

    total =  parseInt(math) + parseInt(science) + parseInt(english) + parseInt(nepali) + parseInt(social)

  var r=document.getElementById("txttotal");


    return total





<form name="frmtotal">

Math<input type="text" name="txtmath" /><br />

Science<input type="text" name="txtscience" /><br />

English<input type="text" name="txtenglish" /><br />

Nepali<input type="text" name="txtnepali" /><br />

Social<input type="text" name="txtsocial" /><br />

<input type="button" value="Total" onclick="calculateMarks(document.frmtotal.txtmath.value, document.frmtotal.txtscience.value, document.frmtotal.txtenglish.value, document.frmtotal.txtnepali.value, document.frmtotal.txtsocial.value)" />

total<input type="text" id="txttotal" />





About Author provides tutorials related to tech and programmings. We are also setting up a community for the users and students.