codice:
<head>
<script>
function somma()
{
var importi = document.getElementsByTagName("input")
var tot = document.getElementById("totale").innerHTML
for(var i=0; i<importi.length; i++){
if(importi[i].type=='checkbox' && importi[i].checked){
document.getElementById("totale").innerHTML = (parseInt(tot)+parseInt(importi[i].value))
}else{
document.getElementById("totale").innerHTML = (parseInt(tot)-parseInt(importi[i].value))
}
}
</script>
</head>
body
codice:
<form method="post" name="preventivo">
Fare il muro : <input type="checkbox" name="muro" value="500" onclick="somma();" />
Fare la cucina : <input type="checkbox" name="cucina" value="1500" onclick="somma();" />
Fare il bagno : <input type="checkbox" name="bagno" value="2000" onclick="somma();" />
</form>
Totale preventivo : <span id="totale">0</span>