This is a very simple example of adding 2 numbers in JavaScript.  Here, we are displaying a total using our custom getTotal() function. <html> <head> <title>JavaScript Tutorial </title> <script type="text/javascript"> function getTotal(){ var first = document.getElementById('first') .value; var second = document.getElementById('second') .value; var total = parseInt(first) + parseInt(second); document.getElementById('total') .value = total; } </script> </head>