• Javascript help required

# Javascript help required

Community Beginner ,
Jul 06, 2022 Jul 06, 2022

Copied

Hi all, I need help, I have created a form that has value fields, and I'm looking for a script to calculate the total of these fields, and IF the sum value of these fields combined is greater than the value of 40 I want the total to display 40, if it is less than 40 I want it to calculate and display the fields totals,

I know in excel calculations is like this is IF(SUM(e1:e17)>40,40,SUM(e1:e17))

I just need a javascript to do the same if it is possible

The fields I need the calculation is "EF1" to "EF16" plus "ExhibitFee" to be placed in a field named "SubTotal"

Cheers Geoff

TOPICS
JavaScript

Views

38

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Community Beginner , Jul 06, 2022 Jul 06, 2022

Hi again,

I found a solution to my question, I created a hidden field with the totals of the required fields, then thanks to youtube I found a video, this is the script I have found that worked, so happy I did my very first javascript &colon;)

var sub = this.getField("HiddenSubTotal").value;

if(sub>40){event.value = "40"}
else {event.value = sub};

Likes

4 Replies 4
Community Beginner ,
Jul 06, 2022 Jul 06, 2022

Copied

Hi again,

I found a solution to my question, I created a hidden field with the totals of the required fields, then thanks to youtube I found a video, this is the script I have found that worked, so happy I did my very first javascript &colon;)

var sub = this.getField("HiddenSubTotal").value;

if(sub>40){event.value = "40"}
else {event.value = sub};

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 06, 2022 Jul 06, 2022

Copied

Thank you for sharing that solution.

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 07, 2022 Jul 07, 2022

Copied

There is no need for hidden field, you can just use sum(+) in "SubTotal" field and place this script under 'Validate' tab:

if(event.value > 40)event.value = 40;

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Jul 07, 2022 Jul 07, 2022

Copied

LATEST

With little to no experience with Java, I just used what I found this morning unfortunately my document has to go public tonight within my community club, I have to really look into Javascript language, thank you for your suggestion

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Resources