Calculated the currency value.

Yamja
Tera Guru

Hi,

 

I have a requirement that needs to calculate the total cost. Total cost = Number of attendees* estimated cost on each attendee.

 

Please someone provide me the client script for this.

"Number of attendees" is string field,  "estimated cost" is currency field and "total cos"t is currency field.

 

Thank you

1 ACCEPTED SOLUTION

Hi Anand,

I tried this code but no luck.

I came up with the script that working fine. Created 2 onchange clients scripts for number of attendees, Estimated cost.

 

Below is the script:


    var cost = g_form.getValue('u_estimated_cost').substring(4);
    //var costattendee = cost.split(';')[0];
    var cost1 = g_form.getValue('u_estimated_cost.display').replace(/,/g,"");
    var float_cost = parseFloat(cost1, 10);
   
    var attendee = g_form.getValue('u_number_of_attendees');
    var attenddee1 = parseFloat(attendee, 10);

    var total_cost = float_cost * attenddee1;


    g_form.setValue('u_total_cost', 'USD:' + total_cost);
   //Type appropriate comment here, and begin script below
   
}
 
Thanks, I would really appreciate your help.

View solution in original post

4 REPLIES 4

Anand Kumar P
Giga Patron
Giga Patron

Hi @Yamja,

You can use below script and change field backend names according to your request

var numberOfAttendees = g_form.getValue('number_of_attendees');
var estimatedCostPerAttendee = g_form.getValue('estimated_cost');

if (numberOfAttendees && estimatedCostPerAttendee) {
var totalCost = parseFloat(numberOfAttendees) * parseFloat(estimatedCostPerAttendee);
g_form.setValue('total_cost', totalCost.toFixed(2));
}

 

Thanks,

Anand

Hi Anand,

I tried this script in client script as onchange with field name as "total estimated cost". But I was unable to get the value of total cost depends those two fields.

Below is the screeshot of script.

Yamja_0-1697049193738.png

 

Below is the screenshot example values:

Yamja_1-1697049264614.png

 Please let me know if I need to add anything.

Thank you,

Theja

Hi @Yamja,

Try below script 

var numberOfAttendees = g_form.getValue('number_of_attendees');
var estimatedCostPerAttendee = g_form.getValue('estimated_cost');

if (numberOfAttendees && estimatedCostPerAttendee) {
var attendees = parseInt(numberOfAttendees, 10);

if (!isNaN(attendees)) {
var totalCost = attendees * parseFloat(estimatedCostPerAttendee);
g_form.setValue('total_cost', totalCost.toFixed(2));

Thanks,

Anand

Hi Anand,

I tried this code but no luck.

I came up with the script that working fine. Created 2 onchange clients scripts for number of attendees, Estimated cost.

 

Below is the script:


    var cost = g_form.getValue('u_estimated_cost').substring(4);
    //var costattendee = cost.split(';')[0];
    var cost1 = g_form.getValue('u_estimated_cost.display').replace(/,/g,"");
    var float_cost = parseFloat(cost1, 10);
   
    var attendee = g_form.getValue('u_number_of_attendees');
    var attenddee1 = parseFloat(attendee, 10);

    var total_cost = float_cost * attenddee1;


    g_form.setValue('u_total_cost', 'USD:' + total_cost);
   //Type appropriate comment here, and begin script below
   
}
 
Thanks, I would really appreciate your help.