Hi,

What drupal version are you using? You mmaight want to look at AHAH which is made to work with dynamic forms. It is built-in in Drupal 6. Additionaly there is an excellent AHAH Helper module, which extends functionality of built-in AHA. You dont really need to write any js if the operations are simple, like in your situation. Some usefull links: http://drupal.org/node/348475


Kindest regards,
Adam Ludwinski
mobile: +48 606 107 297
adam.ludwinski@meant4.com
http://www.meant4.com


On 21 February 2010 20:51, Karyn Cassio <karyn@karyncassio.com> wrote:
Hi Everyone,

I hope you are enjoying your weekend and not working too hard.

I'm still trying to get my head around js, and was hoping someone may have some insights to help me with the next steps on a form I am creating.

I have an order form that is going to be dynamically created.
I am able to successfully pass the quantity value upon user input for field 1.
Basically I'm using onchange() to pass the quantity value to the script.
The id of the price field is of the format unit-price-0, unit-price-1, etc.
Each line item's subtotal should update before going onto the next line item.

Here's the js function. Each line item has its own unit-cost, quantity, and subtotal.
Any help would be so appreciated.

One suggestion was to "have form api write those hidden fields after each element is created"
Not sure how to accomplish that.
function calcPrice() {
 
 // Get the Quantity From Form Field //
unitCost = document.getElementById ('edit-price-0').value;   
theQty = document.getElementById ('edit-quantity').value;

 subOrderCost = theQty * unitCost;
   
 //Line Item Cost //
 subtotalCost = subOrderCost;
 //
 subtotalCostDisplay = addCommas(subtotalCost.toFixed(2));
 //
 subtotalCostValue = subtotalCost.toFixed(2);
 //
 //// Display Cost To User //
 document.getElementById('edit-subtotal').value = "$" + subtotalCostDisplay;
}
-- 
Karyn