[development] Form API and Javascript stuck

Karyn Cassio karyn at karyncassio.com
Sun Feb 21 21:08:23 UTC 2010


Using D6.x

Actually, don't think AHAH will work in this case. The issue isn't  
just adding fields, which is my understanding what AHAH does best.  
Each line item has computations on them. For instance, form supplies  
(per line item) item name and a price. Then there is a field for the  
person to enter the quantity they desire (think order form). As soon  
as they enter the quantity, line item subtotal fills. That's where js  
comes in, to do the computation of the line item.

Anyway, the same js will be used for all line items and the line items  
will be different for each field, so hard coding the field id's won't  
work.

I think what I need to do is get the name of the id as well as the  
value so I can split out the name and then perform the function on  
each line item.

Karyn
303.981.4161
Sent from my Phone

On Feb 21, 2010, at 1:53 PM, ad4m <adam at ludwinski.net> wrote:

> 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 at meant4.com
> http://www.meant4.com
>
>
> On 21 February 2010 20:51, Karyn Cassio <karyn at 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20100221/1fab0c2d/attachment.html 


More information about the development mailing list