FIRST ANSWER
You can't do calculations using HTML as it is static, in order to do that you should use javascript or similar solutions.
Try it and come back if you face some problems.
SECOND ANSWER
In order to call a javascript code snippet you will have to create a form and react to the send button:
<form name='Myform' action='file_to_call.html' method='POST' enctype='application/x-www-form-urlencoded' onsubmit='return javascript_function();'>
Here you can see how to call a function before getting into the "file_to_call".
See forms and javascript in html to get more information and good samples on how to implement javascript calls in html.