Ho il seguente codice che calcola il totale del valori di una serie di checkbox e di un valore recuperato con var total = parseInt(document.getElementById('TariffaNotti').i nnerHTML);
Se questo ultimo valore non è formattato con il puntino per le migliaia funziona tutto bene, altrimenti il tutto va in errore. Mi sapete spiegare come posso levare questo puntino?
Grazie infinite!!
codice 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=iso-8859-1" /> <title>Documento senza titolo</title> </head> <body> <p>Tariffa per <b>1 notti</b>: <b><span id="TariffaNotti">2.000,00</span> euro</b>.</p> <input type="checkbox" name="uno" value="30" onClick="test(this);" /> Extra n.1, euro 30,00<br /> <input type="checkbox" name="due" value="50" onClick="test(this);" /> Extra n.2, euro 50,00<br /> <input type="checkbox" name="tre" value="190" onClick="test(this);" /> Extra n.3, euro 190,00<br /> <b>Importo totale : <span id="Totalcost">2.000,00</span></b></p> </body> <script type="text/javascript"> function formatMoney(number, places, symbol, thousand, decimal) { number = number || 0; places = !isNaN(places = Math.abs(places)) ? places : 2; symbol = symbol !== undefined ? symbol : "$"; thousand = thousand || ","; decimal = decimal || "."; var negative = number < 0 ? "-" : "", i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + "", j = (j = i.length) > 3 ? j % 3 : 0; return symbol + negative + (j ? i.substr(0, j) + thousand : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : ""); } var total = parseInt(document.getElementById('TariffaNotti').innerHTML); function test(item){ if(item.checked){ total+= parseInt(item.value); }else{ total-= parseInt(item.value); } totale = formatMoney(total,2, "", ".", ","); //alert(total); document.getElementById('Totalcost').innerHTML = totale; } </script> </html>

Rispondi quotando