Hello,
I need some help with the following code. I know very little javascript, I am more familiar with php. I am working with javascript code, php/mysql backend and smarty templates. I am trying to get the textfield box to update with a variable from the database based on the selection from the drop down field. My dynamic drop down selection works fine, it is pulling the data from the database (example:$item[i].PARTS_RATE_ID}) just fine. But I want the textfield ('parts_price['+iteration+']') to dynamically show the $item[i].PARTS_RATE_COST from the database (in the parts section), associated with the $item array from the "parts description".

function addRowToTableParts(){
var tbl = document.getElementById('parts');
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow + 1
var iteration = lastRow;
var row = tbl.insertRow(lastRow);

// Number
var cellLeft = row.insertCell(0);
var textNode = document.createTextNode(iteration);
row.setAttribute('class', 'olotd4')
cellLeft.appendChild(textNode);

// Count
var cellRight = row.insertCell(1);
var el = document.createElement('input');
el.setAttribute('type', 'text');
el.setAttribute('name', 'count['+iteration+']');
el.setAttribute('id', 'count['+ iteration+']');
el.setAttribute('size', '4');
el.setAttribute('class', 'olotd4');
el.setAttribute('value', '1');
cellRight.appendChild(el);


// Parts Description
var cellRight = row.insertCell(2);
var sel = document.createElement('select');
sel.setAttribute('name', 'parts_description[' + iteration+']');
{/literal}
{section loop=$item name=i}
sel.options[{$smarty.section.i.index}] = new Option('{$item[i].PARTS_RATE_NAME}', '{$item[i].PARTS_RATE_ID}');
{/section}
{literal}
sel.setAttribute('class', 'olotd4');
cellRight.appendChild(sel);


// Price
var cellRight = row.insertCell(3);
var el = document.createElement('input');
el.setAttribute('type', 'text');
el.setAttribute('name', 'parts_price['+iteration+']');
el.setAttribute('id', 'parts_price['+ iteration+']');
el.setAttribute('size', '5');
el.setAttribute('class', 'olotd4');
cellRight.appendChild(el);

}


The html portion looks like this:
{section name=w loop=$parts}
<tr class="olotd4">
<td>{$smarty.section.w.index+1} {if $wo_status != '9'}<a href="?page=invoice:remove&type=p&id={$parts[w].INVOICE_PARTS_ID}&inv_id={$parts[w].INVOICE_ID}&sub={$parts[w].INVOICE_PARTS_SUBTOTAL}&sku={$parts[w].INVOICE_PARTS_SKU}&wo_id={$invoice.WORKORDER_ID}&customer_id={$invoice.CUSTOM ER_ID}" onClick="return window.confirm('Are you SURE you want to remove this part charge?')"><small>Remove</small></a>{/if}</td>
<td>{$parts[w].INVOICE_PARTS_COUNT}</td>
<td>{$parts[w].INVOICE_PARTS_DESCRIPTION}</td>
<td>${$parts[w].INVOICE_PARTS_AMOUNT|string_format:"%.2f"}</td>
<td>${$parts[w].INVOICE_PARTS_SUBTOTAL|string_format:"%.2f"}</td>

</tr>
{/section}

Any help would be greatly appreciated. Thanks in advance.