ciao a tutti,
sto cercando di risolvere un problema da un pò di giorni,
ho una funzione che mi calcola i prezzi in base a due parametri
1) il numero di pezzi
2) se la checkbox e spuntata
non sono lontana dalla soluzione ma sto sicuramente facendo degli errori concettuali e non riesco a venirne fuori, mi dareste una mano la pagina è piccola se volete potete ricostruirla copiando qui
codice:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>CALCOLO CHEKBOX</title>
<script type="text/javascript">
<!--
function resettacheck (){
var e=document.form1.elements;
for(var i=0;i<e.length;i++)
if(e[i].name.indexOf('selezione')>-1 && e[i].type=='checkbox' && e[i].checked)
e[i].checked=false;
document.form1.sez.value = "0";
}
function disabilita (quale){
var s=0;
var e=document.form1.elements;
var pz = parseInt(e['nart'+quale].value, 10);
var prezzo = parseFloat(e['selezione'+quale].value, 10);
var totale = parseFloat(document.form1.sez.value, 10);
if (e['selezione'+quale].checked==true && totale != 0 && pz == 0){
e['selezione'+quale].checked=false;
document.form1.sez.value -= e['selezione'+quale].value;
document.form1.sez.value = Math.round(document.form1.sez.value*100) / 100;
e['selezione'+quale].disabled = false;
}else if (e['selezione'+quale].checked==true && totale != 0 && pz != 0) {
e['selezione'+quale].checked=false;
var diviso = e['selezione'+quale].value * e['nart'+quale].value;
document.form1.sez.value -= diviso;
document.form1.sez.value = Math.round(document.form1.sez.value*100) / 100;
e['selezione'+quale].disabled = false;
}
}
function somma(quale){
var s=0;
var e=document.form1.elements;
var pz = parseInt(e['nart'+quale].value, 10);
var prezzo = parseFloat(e['selezione'+quale].value, 10);
var totale = parseFloat(document.form1.sez.value, 10);
if (pz != 0) {
var tot = prezzo*pz;
s =tot+totale;
s= Math.round(s*100) / 100;
alert(s);
document.form1.sez.value = s;
e['selezione'+quale].disabled = true;
}else{
for(var i=0;i<e.length;i++)
if(e[i].name.indexOf('selezione')>-1 && e[i].type=='checkbox' && e[i].checked)
s +=parseFloat(e[i].value);
s= Math.round(s*100) / 100;
alert(s);
document.form1.sez.value = s;
e['selezione'+quale].disabled = true;
}
}
//-->
</script>
<style type="text/css">
<!--
.Stile3 {color: #FFFFFF}
.Stile21 {color: #FF0000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; }
.Stile22 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; }
.Stile23 {font-size: 11px}
.Stile25 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #000000;}
-->
</style>
</head>
<body>
<form name="form1" method="post" action="">
<table width="200" border="0" cellpadding="5" cellspacing="15">
<tr>
<td nowrap><span class="Stile21">PZ.
<input name="nart22" type="text" id="nart22" onFocus="disabilita (22)" value="0" size="5" maxlength="4"> € 18.64</span>
<span class="Stile22">
<input name="selezione22" type="checkbox" id="selezione22" onClick="return somma(22)" value="18.64">
</span></td>
<td nowrap><span class="Stile21">PZ.
<input name="nart60" type="text" id="nart60" onFocus="disabilita (60)" value="0" size="5" maxlength="4"> € 17.13</span>
<span class="Stile22">
<input name="selezione60" type="checkbox" id="selezione60" onClick="return somma(60)" value="17.13">
</span></td>
</tr>
<tr>
<td colspan="2" nowrap><span class="Stile23"></span><span class="Stile23"></span></td>
</tr>
<tr>
<td colspan="2" nowrap><div align="right"><span class="Stile3"><span class="Stile25">TOTALE ARTICOLI €</span></span><span class="Stile3"><span class="Stile25">
<input name="sez" type="text" id="sez" value="0" size="6" maxlength="6">
</span></span></div> </td>
</tr>
<tr>
<td colspan="2" nowrap><div align="right"><span class="Stile3"><span class="Stile25">RESET FORM </span></span></div> <div align="left"><span class="Stile3"><span class="Stile25"></span></span></div></td>
</tr>
</table>
</form>
</body>
</html>
Vi pregodatemi una manina
Grazie