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

Custom Calculation Javascript

New Here ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

Hello, I apolgize if this isn't the write place to request this, but was hoping could get help with a custom calculation script. I see similar calculation script posts but not too good with code to change to this specficiation. 

 

I would like to set the field to "Number" format category (no decimals, just initally), but when they enter the number it calculates this way:

  • Make the formula divide the number entered by 10,000, (e.g. so value 40 entered gets displayed as “0.0040”)

 

Thank you for any help in advance

TOPICS
How to , JavaScript , PDF forms

Views

966

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 Expert , Jun 22, 2021 Jun 22, 2021

In that case you can't use the Number format. Check it to Custom and as the custom Format script enter the following:

 

if (event.value) event.value = event.value/10000;

Votes

Translate

Translate
Community Expert ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

Do you want to actually change the value they enter, or just display it in this way?

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
New Here ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

The value can remain the same, I just want it to be displayed as the decimal/calculation. 

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 ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

In that case you can't use the Number format. Check it to Custom and as the custom Format script enter the following:

 

if (event.value) event.value = event.value/10000;

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
New Here ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

This is great, thank you very much. Is there anyway to include in the code an option to restict the value to number format? 

 

Either way this is very helpful and works as intended. 

 

Thank you again for your time and help!

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 ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

LATEST

You would need to use a custom keystroke or validation script for that.

For the latter you can use something simple, like this:

 

if (isNaN(Number(event.value))) {

event.rc = false;

app.alert("You must enter a number.");

}

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