Following is the html code for your reference:
First variable(A):<input id="a11" name="a11" type="text" /></br>
Second variable(B):<input id="a21" name="a21" type="text" /></br>
<button onclick="javascript:showJavascriptAlert()" type="button">Click to Add (A+B)</button><br />
Total(=A+B):<input id="a31" name="a31" readonly="" type="text" /><br />
<script language="JavaScript">function showJavascriptAlert(){document.getElementById("a31").value=+document.getElementById("a11").value + +document.getElementById("a21").value;}</script>