• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Javascript help required

Community Beginner ,
Jul 06, 2022 Jul 06, 2022

Copy link to clipboard

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

366

Translate

Translate

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 guidelines

correct answers 1 Correct answer

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 :) 

 

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

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

Votes

Translate

Translate
Community Beginner ,
Jul 06, 2022 Jul 06, 2022

Copy link to clipboard

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 :) 

 

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

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

Votes

Translate

Translate

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 guidelines
Community Expert ,
Jul 06, 2022 Jul 06, 2022

Copy link to clipboard

Copied

Thank you for sharing that solution.

Votes

Translate

Translate

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 guidelines
Community Expert ,
Jul 07, 2022 Jul 07, 2022

Copy link to clipboard

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;

Votes

Translate

Translate

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 guidelines
Community Beginner ,
Jul 07, 2022 Jul 07, 2022

Copy link to clipboard

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 

Votes

Translate

Translate

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 guidelines