Difference between revisions of "Multiple product calculation"

From All n One's bxp software Wixi

Jump to: navigation, search
(JavaScript code to calculate the total cost of different combination of products from a list of multiple drop down lists)
 
 
(3 intermediate revisions by one other user not shown)
Line 8: Line 8:
  
 
== Create the Variables ==
 
== Create the Variables ==
 +
  
 
''var tempCost = 0;''
 
''var tempCost = 0;''
Line 24: Line 25:
  
 
''int_times[5]=0;''
 
''int_times[5]=0;''
 +
  
 
''var int_star=new Array();''
 
''var int_star=new Array();''
Line 44: Line 46:
 
          
 
          
 
         int_times[0]=1.90; And the rest of the array will be all set to zero
 
         int_times[0]=1.90; And the rest of the array will be all set to zero
 
  
 
== Getting the selected values from the Drop down lists ==
 
== Getting the selected values from the Drop down lists ==
  
  
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times mon''
+
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times Monday issue''
  
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times tue''
+
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times Tuesday issue''
  
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times wed''
+
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times Wednesday issue''
  
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times thur''
+
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times Thursday issue''
  
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times fri''
+
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times Friday issue''
  
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times sat''
+
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times Saturday issue''
 
 
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star mon''
+
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star Monday issue''
  
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star tue''
+
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star Tuesday issue''
  
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star wed''
+
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star Wednesday issue''
  
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star thur''
+
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star Thursday issue''
  
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star fri''
+
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star Friday issue''
  
 
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star sat''
 
''var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star sat''
Line 77: Line 78:
 
       This is getting the values that are associated with the the drop down lists in the campaign  
 
       This is getting the values that are associated with the the drop down lists in the campaign  
 
       To adapt this to a new campaign where it says 'strCDA_X_field_0_X ' simply swap the 'X' for the numbers associated fields in your campaign
 
       To adapt this to a new campaign where it says 'strCDA_X_field_0_X ' simply swap the 'X' for the numbers associated fields in your campaign
 
 
  
 
== Calculating the Cost of the combinations of the products selected ==
 
== Calculating the Cost of the combinations of the products selected ==
Line 110: Line 109:
 
       To adapt this to a new campaign where it says 'strCDA_X_field_0_X ' simply swap the 'X' for the numbers associated fields in your campaign
 
       To adapt this to a new campaign where it says 'strCDA_X_field_0_X ' simply swap the 'X' for the numbers associated fields in your campaign
 
----
 
----
 +
 +
 +
[[Category:Module Specific:Form Management]]
 +
[[Category:Topic:JavaScript]]

Latest revision as of 03:01, 22 March 2014

1 Description

    This demo will use the example of two newspapers with different prices based on the day of the week.
    If a sales rep goes to the client the client will be able to select the newspaper issues that he/she wants. The code will also calculate the weekly cost of the combination
    of the issues that the client wants to purchase.


2 Create the Variables

var tempCost = 0;

var int_times=new Array();

int_times[0]=0;

int_times[1]=0;

int_times[2]=0;

int_times[3]=0;

int_times[4]=0;

int_times[5]=0;


var int_star=new Array();

int_star[0]=0;

int_star[1]=0;

int_star[2]=0;

int_star[3]=0;

int_star[4]=0;

int_star[5]=0;


       This creates two arrays for the two newspapers with the ability to store the price for six days
       e.g. if the client want the Times only on a Monday, the array will look like this
       
       int_times[0]=1.90; And the rest of the array will be all set to zero

3 Getting the selected values from the Drop down lists

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times Monday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times Tuesday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times Wednesday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times Thursday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times Friday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Times Saturday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star Monday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star Tuesday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star Wednesday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star Thursday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star Friday issue

var strCDA_X_field_0_X = document.getElementById('strCDA_X_field_0_X ');//Star sat



     This is getting the values that are associated with the the drop down lists in the campaign 
     To adapt this to a new campaign where it says 'strCDA_X_field_0_X ' simply swap the 'X' for the numbers associated fields in your campaign

4 Calculating the Cost of the combinations of the products selected

var temp_Times=int_times[0]+int_times[1]+int_times[2]+int_times[3]+int_times[4]+int_times[5];

        Adds up the values of the selected issues that the client wants for the Times newspaper


var temp_Star=int_star[0]+int_star[1]+int_star[2]+int_star[3]+int_star[4]+int_star[5];

      Adds up the values of the selected issues that the client wants for the Star newspaper

tempCost=temp_Times+temp_Star;

     Combines the value of the times and the star to get a total cost

tempCost=tempCost.toFixed(2);

      This line rounds the value to two decimal places to avoid a total value of 1.569541 and rounds it to 1.57

document.getElementById('strCDA_X_field_0_X').value=tempCost;

       This line then adds the total amount to the pre-selected field that you want the total price to be inserted into.
      To adapt this to a new campaign where it says 'strCDA_X_field_0_X ' simply swap the 'X' for the numbers associated fields in your campaign