[development] Form API and Javascript stuck

Karyn Cassio karyn at karyncassio.com
Sun Feb 21 19:51:56 UTC 2010


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20100221/4f24cede/attachment.html 


More information about the development mailing list