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

Force Javascript to update

Community Beginner ,
Aug 23, 2017 Aug 23, 2017

I have a field that a person enters a value into.  The value has to be entered as a value of 0.5 or 0.  For example:

12.00

12.50

13.00

Those values are acceptable.  A value of 12.25 is not acceptable.  Is there a way to basically not except a value that does not end with a .00 or a 0.50 and just leave the field blank if the operators enters something other then this?

TOPICS
Acrobat SDK and JavaScript
264
Translate
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 ,
Aug 23, 2017 Aug 23, 2017

Yes. Use this code as the field's custom validation script:

if (event.value) event.rc = (Number(event.value)%0.5==0);

Translate
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 ,
Aug 24, 2017 Aug 24, 2017

I am wanting the code to automatically round up to the nearest 0.5

So if the person enters 34.75 then it will round the value up to the nearest 0.5 which would be 35.00

If the person enter 34.25 then it would round up to 35.50

Translate
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 ,
Aug 25, 2017 Aug 25, 2017
LATEST

This is a purely mathematical task. I've written some sample code that demonstrates how to do it:

var a = 34.25;

var round_a = Math.floor(a);

if (a!=round_a) {

    if ((a-round_a)<=0.5)

        a = round_a+0.5;

    else a = round_a+1;

}

console.println(a);

Translate
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