I want to build a basic HTML page with three input variables (A,B,C). After the user inputs these values, they will click "calculate", and JavaScript will execute the following equations:
((A + B)/2) * 3 = X
and
(C * 2) = Y
The results will be displayed as outputs of X
Value and Y
Value.
Here is an image:
https://i.sstatic.net/E40kS.png
I've set up the HTML but am struggling with the JavaScript. Would appreciate any help :) Thank you in advance!
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>Example</title>;
</head>;
<body>
<body class="container">
<div class="row">
<div class="span6">
<h1 align="center">Example</h1>
<form class="form-horizontal well w3-center" style="max-width: 850px; width: 100%; margin: 0 auto;">
<div class="control-group">
<label class="control-label">A</label>
<div class="controls">
<input type="text" name="A" class="ratecalcfield"></input>
</div>
</div>
<div class="control-group">
<label class="control-label">B</label>
<div class="controls">
<input type="text" name="B" class="ratecalcfield"></input>
</div>
</div>
<div class="control-group">
<label class="control-label">C</label>
<div class="controls">
<input type="text" name="C" class="ratecalcfield"></input>
</div>
</div>
<div class="control-group">
<label class="control-label">X Value</label>
<div class="controls">
<input type="text" name="x" class="ratecalcfield"></input>
</div>
</div>
<div class="control-group">
<label class="control-label">Y Value</label>
<div class="controls">
<input type="text" name="y" class="ratecalcfield"></input>
</div>
</div>
<div class="control-group w3-margin-top">
<div class="controls">
<input type="button" class="w3-button w3-blue w3-padding-large" style="max-width: 200px; width: 100%;" onclick="cmdCalc_Click()" value="Calculate" name="cmdCalc"></input>
</div>;
</div>;
</form>;
<script src="js/index.js"></script>;
</body>;
</html>
function cmdCalc_Click() {
calculate();
}
function calculate() {
A = parseInt(document.getElementById("A").value);
B = parseInt(document.getElementById("B").value);
C = parseInt(document.getElementById("C").value);
x = document.getElementById("x");
y = document.getElementById("y");
x.innerHTML = (3 * C);
y.innerHTML = (((A + B) / 2 ) * 2));
}