How to reset calculation when user erase the reference field?

New Here ,
Apr 02, 2022 Apr 02, 2022

Copy link to clipboard

Copied

Hi,

 

I have a field wich the user enters the number of Kilometers they have made, and another field which takes that number times .53. If the number of KM is erased, the previous amount in the second field doesn't reset. How do I make sure that when a user erase the first field content, that the field with the calculation will also reset? Here's my script for the calculation, maybe that's where I'm doing it wrong.

var nKMs= this.getField("KMs").value
var nNumberKM = this.getField("NumberKM").value
if (nNumberKM > 0) event.value = nNumberKM * 0.53

TIA!

TOPICS
JavaScript , PDF forms

Views

76

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
community guidelines
Adobe Community Professional ,
Apr 02, 2022 Apr 02, 2022

Copy link to clipboard

Copied

Remove this part from your code:

if (nNumberKM > 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
community guidelines
New Here ,
Apr 03, 2022 Apr 03, 2022

Copy link to clipboard

Copied

HI Try67,

 

Thanks, but that part is actually what I wanted because I don't want anything displayed in the KMs field if there is nothing in the NumberKM field. That's the only way I found, but maybe there is a better way of doing this. 

 

I want the amount to be displayed for some field only if there are an entry in the NumberKM. If the person doesn't have anything to put in that field, I don't want to see 0.00$ in the KMs field. 

I took the same approche for the tax fields, if the person doesn't have a tax number, than no amount is displayed. Again, that was the only way I found that worked. If you guys have a better way, I'm all for it. But if the field is set to empty afterward, then the problem I have is that the old amount stays in the KMs field, not good.

Thanks again!

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
community guidelines
Adobe Community Professional ,
Apr 03, 2022 Apr 03, 2022

Copy link to clipboard

Copied

Then add this to the end of the original code:

 

else event.value = "";

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
community guidelines
New Here ,
Apr 03, 2022 Apr 03, 2022

Copy link to clipboard

Copied

LATEST

Thanks Try67, this is exacly what I wanted!

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
community guidelines