Programming

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.

<html>

<head>

<script>

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

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

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

  r.value=total;

    return total

  }

</script>

</head>

<body>

<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" />

</form>

</body>

</html>

Tuts

About Author

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