I have a dynamic set of input fields being generated. They all get named sequentially and each has an onFocus() handler. Just before each Input element is a div with a corresponding Id where I grab a dollar value from.

```
<input type="hidden" name="balance" value="2500.0" />  
<div id="invoiceAmount0">$500.00</div>
<input type="text" size="8" id="invoiceBalance0" name="invoiceBalance0" value="" onfocus="setBalance(this)" />
<div id="invoiceAmount1">$500.00</div>
<input type="text" size="8" id="invoiceBalance1" name="invoiceBalance1" value="" onfocus="setBalance(this)" />
<div id="invoiceAmount2">$500.00</div>
<input type="text" size="8" id="invoiceBalance2" name="invoiceBalance2" value="" onfocus="setBalance(this)" />

```

The JS onFocus handler is as follows:

```
function setBalance(e) //e should be an input field element
{
  var balance = document.PaymentForm.balance.value;
  var remainder = balance;

  var index = 0;
  var paymentField = document.getElementById('invoiceBalance'+index);  //get the first input payment element
  while (paymentField != null && paymentField != e) //start with the first field and calculate the remaining balance
  {
    var paymentApplied = paymentField.value.replace(/[^0-9\.]+/g,""); 
    remainder = remainder - paymentApplied;
    index++;
    paymentField = document.getElementById('invoiceBalance'+index);  
  }
  while (e == paymentField)  //set the selected elements value
  {
    var invoiceBalance = document.getElementById('in'+index).innerHTML.replace(/[^0-9\.]+/g,"");
    if (parseFloat(remainder) > parseFloat(invoiceBalance))
      e.value = parseFloat(invoiceBalance).toFixed(2).toLocaleString();    
    else
      e.value = parseFloat(remainder).toFixed(2).toLocaleString();
    index++;
    paymentField = document.getElementById('invoiceBalance'+index); 
  }
  while (paymentField != null)  //blank out the rest of the input fields
  { 
    paymentField.value = ''; 
    index++;
    paymentField = document.getElementById('invoiceBalance'+index); 
  }
  e.select();
}

```

The concept here is to calculate the remaining balance and set the input field's value as the user focuses the fields.

The problem is that The "this" parameter is always set to the first Input element "invoiceBalance0". I'm expecting it to be set to the element referring to it in it's onFocus handler.

What am I not seeing?