you would need to use javascript to assign the value on submit.
I assume you want to insert the sum to a database column?
instead of using javascript to set a hidden element, do the math server side to sed the hidden element.
for example if you have form elements named txt1, txt2 and txtSum, add the following at line 1 of the page:
<?php
if($_SERVER['REQUEST_METHOD'] == "POST") {
$txt1 = (isset($_POST["txt1"]))?intval($_POST["txt1"]):0;
$txt2 = (isset($_POST["txt2"]))?intval($_POST["txt2"]):0;
$txtSum = $txt1 + $txt2;
$_POST["txtSum"] = $txtSum ;
}
?>
bear in mind that this code assumes the use of integers, if you are using floating point numbers, change intval to floatval.