Stay Tuned!

Subscribe to our newsletter to get our newest articles instantly!

JavaScript

JavaScript Program to Calculate the Sum Total

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>
Avatar

Tuts

About Author

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

You may also like

javascript
JavaScript

JavaScript – Introduction, History, and Syntax

  • September 17, 2020
What is “JavaScript”? The first appearance of JavaScript was made in Netscape 2.0 in 1995 with a name Live Script.
javascript
JavaScript

JavaScript – Write Program to Print Hello World!!!

  • September 17, 2020
JavaScript is scripting language which is similar to C. It is syntax and logic are similar to C, C++ and