Force Javascript to update

Aug 23, 2017

Copy link to clipboard

Copied

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

Views

100

Likes

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

Force Javascript to update

Aug 23, 2017

Copy link to clipboard

Copied

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

Views

101

Likes

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
Aug 23, 2017 0
Aug 23, 2017

Copy link to clipboard

Copied

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

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

Likes

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
Reply
Loading...
Aug 23, 2017 0
Aug 24, 2017

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Aug 24, 2017 0
try67 LATEST
Aug 25, 2017

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Aug 25, 2017 0