I'm using the following code for a calculation script, which works fine:
Code:
function startCalc_percentage(){
  interval = setInterval("calc_percentage()",1);
}

function calc_percentage(){
  one = document.formulier.costbase_amount.value;
  two = document.formulier.costbase_margin.value; 
  document.formulier.amount.value = (one * 1) * (two / 100) + (one * 1);
}
The HTML code looks something like this:
Code:
<input type="text" name="costbase_amount" id="costbase_amount" value="" onFocus="startCalc_percentage();" onBlur="stopCalc();"/>
<input type="text" name="costbase_margin" id="costbase_margin" value="" onFocus="startCalc_percentage();" onBlur="stopCalc();"/>
<input type="text" name="amount" value=""/>
I'm generating the HTML code in a loop (with PHP). What I want is to give each set of input fields a unique ID (with PHP), so I would have something like this:

Code:
<input type="text" name="costbase_amount[]" id="costbase_amount1" value="" onFocus="startCalc_percentage();" onBlur="stopCalc();"/>
<input type="text" name="costbase_margin[]" id="costbase_margin1" value="" onFocus="startCalc_percentage();" onBlur="stopCalc();"/>
<input type="text" name="amount[]" value=""/>

<input type="text" name="costbase_amount[]" id="costbase_amount2" value="" onFocus="startCalc_percentage();" onBlur="stopCalc();"/>
<input type="text" name="costbase_margin[]" id="costbase_margin2" value="" onFocus="startCalc_percentage();" onBlur="stopCalc();"/>
<input type="text" name="amount[]" value=""/>

(.. and so on ..)
I could generate the javascript with PHP in a loop to get this to work. But is there a better way? Like giving the number as a variable to the script. I tried to get this to work, but due to my lack of js knowledge I didn't get it to work.