function getFoobarFromUser(elementid) {
var foobar = parseFloat(document.getElementById(elementid).innerHTML)
if (isNaN(foobar)) foobar = 3.21; // default value
return(foobar.toFixed(2));
}
<script src="/common/tools/jquery-1.10.2.js"></script>
<script src="/common/tools/jquery-ui.js"></script>
<!--------- link above two lines to your jQuery files ------>
<script type="text/javascript">
function calculate_subtotal(){
$('#quantity').val((+$('#quantity').val() || 0));
$('#unit').val((+$('#unit').val() || 0));
var calculated = $('#quantity').val() * $('#unit').val();
$('#subtotal').val(calculated);
}
</script>
<input type = "text" onChange ="calculate_subtotal();" id = "quantity"/>
<input type = "text" onChange ="calculate_subtotal();" id = "unit"/>
<input type = "text" id = "subtotal"/>