ti ringrazio per la guida che mi hai sugerito ho letto un po il tutto e sono riuscito a farlo funzionare in parte

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 a modificarlo

Codice PHP:
<script>
function somma() { 
var a=eval(document.getElementById("primo").value) ; 
var b=eval(document.getElementById("secondo0").value);
var somma0=(a) - ((a) * (b)) / 100;
var somma0=Math.round(somma0 * 100) / 100;
document.getElementById("somma0").value=somma0; 

var b1=eval(document.getElementById("secondo1").value);
var somma1=(a) - ((a) * (b1)) / 100;
var somma1=Math.round(somma1 * 100) / 100;
document.getElementById("somma1").value=somma1; 

var b2=eval(document.getElementById("secondo2").value);
var somma2=(a) - ((a) * (b2)) / 100;
var somma2=Math.round(somma2 * 100) / 100;
document.getElementById("somma2").value=somma2; 

var b3=eval(document.getElementById("secondo3").value);
var somma3=(a) - ((a) * (b3)) / 100;
var somma3=Math.round(somma3 * 100) / 100;
document.getElementById("somma3").value=somma3; 

var b4=eval(document.getElementById("secondo4").value);
var somma4=(a) - ((a) * (b4)) / 100;
var somma4=Math.round(somma4 * 100) / 100;
document.getElementById("somma4").value=somma4; 
}
</script>
<input type="text" id="primo" onKeyUp="somma()" />


<?php 
for($i=0;$i<=4;$i++)
 {
?>

<input type="text" id="secondo<?php echo $i?>" name="secondo" onKeyUp="somma()" value="6" />
<input type="text" id="somma<?php echo $i?>" />

<?php 
 
}
?>