Ready to get started?

Help Files / User Guides

Review the new and improved user guides including instructions on setting up the Dynamic Forms module, explanation of features,  product information, and more!

 

User Guide (PDF)

 

Demonstrations

View Dynamic Forms Demonstrations

Dynamic Forms Video Tutorial

 

Trial Version

Dynamic Forms 3.1 Trial

 

Purchase Dynamic Forms

Dynamic Forms 3.1 w/ Snowcovered


 

License Agreement

Standard Version

Enterprise Edition

 

Recently Viewed...
DNN Modules
   
    |   Register   |   Tuesday, March 16, 2010   
You are here:Products  DNN Modules  Dynamic Forms  Dynamic Forms Demonstration 20 - Calculations  


Dynamic Forms Demonstration 20 - Advanced field options and client events...

 

Section 1:  Radio Buttons


This section demonstrates a calculation performed with the use of radio buttons.  Radio buttons are best used for single selections like membership types.  In this scenario, we're offering 3 different service plans.  Notice that the Bronze plan is the default selection.  You can alter this setting under Advanced Field Options.  The price of the service will be automatically displayed beneath the radio buttons based on your choice. 

 




Your total comes to: $0.00

 

Section 2:  Drop-down Menu


This section demonstrates a calculation performed by choosing values from 2 drop-down menus. This is a great solution if you want to offer a combination of products in different categories.  The total value for the fees ("Apples" and "Baskets") will be calculated based on the values chosen from the pull down menu.

 



Your total comes to: $0.00

 

Section 3:  Check Box List


This section demonstrates a calculation performed by selecting check boxes, i.e. the products.  Note that, unlike a radio button, a check box list will allow for multiple selections.  The total value for all selected products will be displayed in the Text/HTML field.   

 





Your total comes to: $0.00

 

 

Section 4:  Textbox



 

 

Section 5:  Total by Quantity


In this section, we will demonstrate how to obtain totals based on a fixed unit price multiplied by the quantity entered.  For this example, the unit price is $ 10.00.

 


Your total here comes to: $0.00

 

 

Your Grand Total...


Your grand total comes to: $0.00



      
Dynamic Forms Demonstration # 20 -- Advanced Calculations

 

This demonstration provides options for obtaining totals using client-side calculations.  A variety of field types are used for this demo, including radio buttons, dropdowns, and checkbox lists.  At the end of the form, we will obtain a grand total, summing up totals obtained from each section.


 

The first thing to note when obtaining totals is that the client-side events are not entered in the total field.  Instead, they are entered in the field that provides the options.  Let's go over each of the examples in the form above.

 

Section 1:  Radio Buttons
 

Take a look at the field that says "What plan do you want to purchase?"  This is the field where you want to put the client-side event.  This is the content of the client side event box:

 

 

Total.innerHTML = 'Your total comes to:  ' '$' funcRadioCalc($(Plans_FieldID)) '';

$(TotalRadio) = funcRadioCalc($(Plans_FieldID))
 

(There are others in this box pertaining to Grand Total calculations which will be discussed later.)

 

This Total.inner/HTML refers to the  Text/HTML field that says "Your total comes to:"  This field  is a good way to offer your users the total amount while preventing them from altering the total amount.

 

However, this field type will not work when passing amounts to payment gateways.  Since Radio Buttons only allow for single selection, you can simply use the option value to pass data to the payment gateway.   In this case, we set the option value of  Gold to 20 as you can see in the image below.   When setting the parameters in your payment gateway, you can use the token $(Plans) since Plans is the short field name for the radio button.

 

 

  

Section 2:  Dropdown Menu

 

In this example, we want to obtain the total by adding the values from Apples and Baskets.  Here are the calculations for these fields:

 

 

$(total) = parseInt($(Apples)) parseInt($(Baskets));

TotalCombo.innerHTML = 'Your total comes to:  ' formatCurrency($(total)) '';

 

 (There are others in this box pertaining to Grand Total calculations which will be discussed later.)

 

Note that the same calculation should be added to the client-side event both the Fee1 and  the Fee2 field.

 

 Section 3:  Check Box List

 

The checkbox list allows users to make multiple selections (as opposed to single selections for  radio buttons).   Look at the calculations used for this field type in this demo:

 

 

$(CheckTotal) =CalculateCheckBoxListValues($(Products_FieldID), $(Products_ValueFieldID));

Total2.innerHTML = 'Your total here comes to:  '   formatCurrency(CalculateCheckBoxListValues($(Products_FieldID), $(Products_ValueFieldID))) '';

 

 (There are others in this box pertaining to Grand Total calculations which will be discussed later.)

 

Section 4:  Textbox

 

In this section,  we offer a textbox here where users can enter their own amount.  A Donation box is a good example where this implementation is suitable.  

 

 {

if(isNaN($(TotalExtraonkeypress))){
$(TotalExtraonkeypress) = '0';
}

 (There are others in this box pertaining to Grand Total calculations which will be discussed below.)

 

Section 5:  Total by Quantity

 

The demonstration in this section is ideal for situations where users can purchase multiples of a fixed-price item such as event tickets.  In the box below, you'll find the client-side event used for this calculation.

 

$(TotalbyQuantity) = (parseInt($(Quantity) *10.00)).toFixed(2);

QTotal.innerHTML = 'Your total here comes to:  ' (parseInt($(Quantity) *10.00)).toFixed(2) '';

 (There are others in this box pertaining to Grand Total calculations which will be discussed below.)

 

 


 

 

The Grand Total

 

As you can see from our demonstration all sub-totals from each section are added together to get to the Grand Totals.    There are 2 grand total fields:  one that's hidden and one that's a Text/HTML.  The javascript shown below for the grand total must be added to client side events of each field that contains the calculations. 

 

 


$(GrandTotalHidden) = formatCurrency(eval(parseFloat($(TotalExtraonkeypress)) parseInt($(TotalRadio)) parseInt($(TotalbyQuantity)) parseInt($(total)) parseFloat($(checktotal))))

GrandTotal.innerHTML = 'Your grand total comes to:  ' formatCurrency($(GrandTotalHidden)) '';

 

 

 Final Thoughts:

 

As mentioned at the beginning of the tutorial, the calculations are entered in the fields that offer the options or where the values are entered, not in the Total fields.  In addition, please visit the Module Configuration and go down to Custom Javascript File and take a look at the Initial Javascript.  This works hand-in-hand with your client-side events so it's important to set this up correctly.

Also note that having the Text/HTML field to display totals is not necessary.  However, it helps prevent users from altering the total amount.  If you choose to use the Text/HTML field, you will need a hidden textbox field to pass data to your payment gateway.  For this demonstration, we created a field called GrandTotalHidden.  You'll find this field if you go to Manage Questions, Select Dynamic Field. 

 

In addition, this article on JavaScript Math FAQs is a good resource for helpful tips.  Check it out!

 

  

Would you like to setup your form just as this demonstration is setup? If so simply download this template and copy it to your DNN Portals Home Directory to use the IPORTABLE feature of the module (Select Import Content from the module menu and import the template):

 

 

 

Feedback Comments
Records per Page
Page 1 of 1First   Previous   [1]  Next   Last   
Candace Host Account         3/11/2010 11:23:34 AM
Response to Gustavo Glad to hear that how much you like the module, Gustavo! Thanks! There are so many variations in tax calculations and it' hard to come up with a solution that will fit all. However, we can help you out with Premium Support. Just let us know what you need at this form: http://www.datasprings.com/contactus.aspx -- Candace Submitted By: Candace Host Account

Gustavo         3/9/2010 8:37:00 AM
Hello Hi, I'm very happy with this module, great work! easy to understand and follow, however, I was wondering if there's a way we could add a field or something in the js formula to calculate the taxes on the Grand Total, after all I don't think it must be so complicated, however I've done my research but have been unable to. Thanks for your valuable help and support! Submitted By: Gustavo

Gustavo         2/26/2010 10:40:55 AM
Problems making this work Hi, I'm trying to make the form work, I exported the XML to my page and doesn't work, apparenty it's about the javascript that goes at << Module Configuration > Custom Javascript File > Initial Javascript >>. What am I supossed to enter here, where's the JS code that has to be written here, I've looked everywhere but I haven't been able to find a solution. thanks in advance for your help Submitted By: Gustavo

Clyde Graham         11/3/2009 12:21:27 PM
Form Help I wasnt able to get it to work either. I am not real sure where the jscript needs to go. Which field, the one for the comb, radio, etc button or the html field. Submitted By: Clyde Graham

Sean         10/1/2009 5:37:03 AM
Still not working Having the same issue as Marc & mark. Can't get the demo to update with totals. Have read the remark of David to add: document.getElementById ('innerHTMLIDName').innerHTML to all javascripts. but no idea where to put that Anyone can explain how to do that exactly? thanks! Submitted By: Sean

David         8/10/2009 3:51:34 PM
problem with seeing fields update HI, you will need to add the following to all javascript section that accesses the innerHTML: document.getElementById ('innerHTMLIDName').innerHTML where 'innerHTMLIDName' is the ID of the inner HTML which you can see by using the RTE and clicking on "SOURCE" icon. David Submitted By: David

Mark         8/10/2009 5:25:13 AM
fields are not updating Having the same issue as Marc below. Downloaded the XML file and only the Total by Quantity updates. None of the other fields are updating. Submitted By: Mark

marc         7/26/2009 11:49:24 PM
not working I have imported the XML and the form will not update the HTML fields. I also have this issue in the registration module where I an trying to use radio buttons to send to an html field and PGateway. Is this a site settings issue with Javascript etc? Submitted By: marc

Chris         3/11/2009 8:45:14 AM
Radio Buttons Issue and fucRadioCalc vs funcRadioCalc I installed the demo version of 2.7. Then imported the iportable file for this demo. The "What do you want to purchase?" field does not calculate a total. I discovered that the Javascript File has no fucRadioCalc, but rather funcRadioCalc (see below). However, after updating the Initial Javascript and question Client side event there is still no calculation. Is there a difference between the fucRadioCalc and funcRadioCalc versions of this function? /*********************************************** * This function call is used to return the value of a radio button. This function can be called for using calculations with radio buttons * Example use: funcRadioCalc($(ShortFieldName_FieldID)) ***********************************************/ function funcRadioCalc(RadioName) { var chkList1= document.getElementById (RadioName); var arrayOfCheckBoxes= chkList1.getElementsByTagName("input"); for(var i=0;i

Steve Carmeli         1/20/2009 8:55:26 PM
sacre blu Great job, guys! Submitted By: Steve Carmeli

Feedback





Enter the code shown above in the box below
Send

 
Copyright 2005 - 2010 by Data Springs, Inc.
Contact Us | Terms Of Use | Privacy Statement