ho apportato delle modifiche allo script solo che la funzione è troppo lunga ed è limitata a 5 elementi si puo semplificare e farla funzionare per n elementi
mi dareste un aiuto che non riesco
Codice PHP:
<script>
function somma() {
var a=document.getElementById("primo").value;
var b0=document.getElementById("secondo0").value;
var somma0=(a) - ((a) * (b0)) / 100;
var somma0=Math.round(somma0 * 100) / 100;
document.getElementById("somma0").value=somma0;
var b1=document.getElementById("secondo1").value;
var somma1=(a) - ((a) * (b1)) / 100;
var somma1=Math.round(somma1 * 100) / 100;
document.getElementById("somma1").value=somma1;
var b2=document.getElementById("secondo2").value;
var somma2=(a) - ((a) * (b2)) / 100;
var somma2=Math.round(somma2 * 100) / 100;
document.getElementById("somma2").value=somma2;
var b3=document.getElementById("secondo3").value;
var somma3=(a) - ((a) * (b3)) / 100;
var somma3=Math.round(somma3 * 100) / 100;
document.getElementById("somma3").value=somma3;
}
<input type="text" id="primo" onKeyUp="somma()" /><br /><br />
<?php
for($i=0;$i<=3;$i++)
{
?>
<input type="text" id="secondo<?php echo $i; ?>" name="secondo" onKeyUp="somma()" value="6" />
<input type="text" id="somma<?php echo $i; ?>" /><br />
<?php
}
?>
dalla funzione precedente vorrei che uscisse un funzione tipo questa o migliore!
Codice PHP:
<script>
function somma() {
a=eval(document.all.prima.value);
for (var i=0; i<seconda.length; i++) {
b=eval(document.all.seconda[i].value);
c=a+b;
}
document.all.terza.value=c;
}
</script>