Tengo este script que me suma bien las cantidades pero al restarlas me convierte las cantidades a números negativos...
Código HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Documento sin título</title> <script type="text/javascript"> function agrega_resultado(campo){ total=parseFloat(document.getElementById('HDNtotal').value); actual=parseFloat(campo.value); if(campo.checked==true){ sum=total+actual; }else{ sum=total-actual; } document.getElementById('total').innerHTML=sum; } </script> </head> <body> <table width="450" border="1"> <tr> <td width="41">Check1</td> <td width="393"> <label> <input type="checkbox" name="CHK1" id="CHK1" onclick="agrega_resultado(this)" value="10"/> </label> </td> </tr> <tr> <td>Check2</td> <td><label> <input type="checkbox" name="CHK2" id="CHK2" onclick="agrega_resultado(this)" value="20"/> </label></td> </tr> <tr> <td>Check3</td> <td><label> <input type="checkbox" name="CHK3" id="CHK3" onclick="agrega_resultado(this)" value="30"/> </label></td> </tr> <tr> <td>Total:</td> <td> <input type="hidden" name="HDNtotal" id="HDNtotal" value="0"/> <div id="total"></div> </td> </tr> </table> </html>
De antemano muchas gracias!