Situation: It has the form and one of the options I want is that it results in a sum of variables automatically by clicking a button or it can be without clicking, just the user just typing the values.
The problem is: he is already activating the action for the php page processing without the user completing the form. How could I do to show the result of the sum below the sum button (the same one that is activating the action)?
code not header:
<script type="text/javascript">
function calcula(){
var val1 = document.getElementById("pa").value;
var val2 = document.getElementById("di").value;
var val3 = document.getElementById("insc").value;
var val4 = document.getElementById("outr").value;
var soma = parseFloat(val1)+parseFloat(val2)+parseFloat(val3)+parseFloat(val4);
document.write("" + soma);
}
</script>
Now the code inside the html form that calls the function above:
<legend>Calcular total.</legend>
<button id="calcular" onclick="calcula()">Calcular</button>
I accept suggestions for doing it in another way or another language.