Fill textfield on select from drop down list

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.CUSTOMER_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>

                                                    &lt;/tr&gt;
											{/section}

Any help would be greatly appreciated. Thanks in advance.

This is the part where you would set that value:


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');

with something like:

[highlight="javascript’]
el.setAttribute(‘value’, $parts[w].PARTS_RATE_COST);



Please note though that I have no experience with smarty templates, so take this info with a hefty grain of salt, and many well-wishes from your family this [s]holiday season[/s]christmas.

Even as an atheist I feel distaste for the extremes of politically correct speech :)

Thanks for help, but did not work. It actually prevents my the text field from showing. I think it may have something to do with smarty templates. Anyone else have any other suggestions?
Thanks everyone and Merry Christmas.