Quito el php,
Trabajo con enteros (100,50 --> 10050) para eliminar los problemas de redondeos...
Recuerda formatear precio antes de guardarlo en la bbdd.... 100,50 ---> 100.50
Quim
Código HTML:
Ver original<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript" type="text/JavaScript"> function suma(obj){
total=parseInt(document.getElementById("precio").value.replace(",",""));
if(obj.checked){
total+=parseInt(obj.value);
}else{
total-=parseInt(obj.value);
}
txttotal=total+"";
if (txttotal=="0") txttotal="000";
document.getElementById("precio").value=txttotal.substring(0,txttotal.length-2)+","+txttotal.substring(txttotal.length-2);
}
<table width="50%" border="1" cellspacing="0" cellpadding="0"> <td> 10,50€
</td> <td><input type="checkbox" name="exc1" id="exc1" value="1050" onChange="suma(this)"/></td> <td>Paseo en bote
</td> <td> 20,00€
</td> <td><input type="checkbox" name="exc2" id="exc2" value="2000" onChange="suma(this)"/></td> <td> 30,30€
</td> <td><input type="checkbox" name="exc3" id="exc3" value="3030" onChange="suma(this)"/></td> <td><input type="text" name="precio" id="precio" value="0,00" /></td>