Javascript set input value based on select in an array
<p>I've found lots of useful help in previous questions, but can't seem to get the last piece I need.  I use PHP to loop through form fields and uniquely name the fields (using a variable).  One of my fields is an "expense type".  Another is "expense amount".  I'd like the expense amount to auto display a mileage rate if "mileage" is the expense selected.  I can do this outside of the array, but in the array I'm having trouble getting the names right in the array.  The PHP code and the rest of the form work perfectly, just the javascript isn't finding the right fields to trigger/update.  Here's the code:</p>

<pre><code>&lt;?php 
$t = -1;
foreach($details as $detail)
{
    $t++;
    echo '&lt;th&gt;&lt;select name="record['.$t.'][expense]" onChange="mileage();" &gt;&lt;option value=""&gt;Expense&lt;/option&gt;';
    foreach($expensecoderesults as $code)
        {
            echo '&lt;option value="'.$code-&gt;expense_code_id.'"';
            if($code-&gt;expense_code_id == $expense_type_id){echo 'selected="selected" ';}
            echo '&gt;'.$code-&gt;expense_code_name.'&lt;/option&gt;';
        }
        echo '&lt;/select&gt;&lt;/th&gt;&lt;/tr&gt;';
        echo '&lt;th&gt;&lt;input type="number" "step=".01" name="record['.$t.'][amount]" /&gt;&lt;/th&gt;';
}
?&gt;
&lt;script language="javascript" type="text/javascript"&gt;
function mileage()
{
    var myForm = document.forms.edit_emp_exp;
    var myControls = myForm.elements['record[][expense]'];
    var myAmount = myForm.elements['record[][amount]'];
    for (var i = 0; i &lt; myControls.length; i++)
    {
        if(myControls.value == 28)//28 is the id of "mileage" expense
        {myAmount.value=".54";}
    }
}
</code></pre>

<p></p>