Labels

Cerpen (18) html (16) movie (10) modul (7) SAP Security (2) c++ (2) Business (1)

Monday, 29 February 2016

Addition operation

<!DOCTYPE html>
<html>
<head>
<title>Calculation additon and average for 4 number</title>
<p><u>This calculate total and average</u></p>
<script language="javascript">
function calc()
{
var bttntotal = document.getElementById("B1");
var bttnaverage = document.getElementById("B2");
var mark1 = parseFloat(document.Marks.mark1.value);
var mark2 = parseFloat(document.Marks.mark2.value);
var mark3 = parseFloat(document.Marks.mark3.value);
var mark4 = parseFloat(document.Marks.mark4.value);
if (bttntotal.checked){
document.Marks.result.value = mark1+mark2+mark3+mark4;
}else if (bttnaverage.checked) {
document.Marks.result.value = ( mark1+mark2+mark3+mark4)/4;
}
}
</script>
</head>
<body>
<form name="Marks">
<ul style type=none>
Marks: <input type="text" name="mark1" min="0" max="100"><br><br>
Marks: <input type="text" name="mark2" min="0" max="100"><br><br>
Marks: <input type="text" name="mark3" min="0" max="100"><br><br>
Marks: <input type="text" name="mark4" min="0" max="100"><br><br>
</ul>
<ul>
<input type="radio" name="calculate" value="bttntotal" id="B1">Find Total &nbsp
<input type="radio" name="calculate" value="bttnaverage" id="B2">Find Average<br></br>
<input type="button" value="Submit" onclick="calc()"> &nbsp &nbsp &nbsp &nbsp
<input type="reset" value="Clear"/>
<br></br>Result: <input type="text" name="result"><br>
</ul>
</form>
</body>
</html>

No comments:

Post a Comment