Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.

• The value entered does not match the format of the...

The value entered does not match the format of the field

New Here ,
Jun 25, 2021 Jun 25, 2021

Copied

Hi I have had a read few of the forums around this topic but havent found what I am looking for. I am very new to this and am looking for a simple solution.

I have two calculations that I need to do:

1. Weight / height^2 (which I have written as (Weight/(Height/100*Height/100)) as we write our height in cm not m

2. Waist / Hip

I am able to get the calclautions working however I need them to be to 2 decimal places which can be changed under the format tab however the above error message keeps coming up - I know this comes up because you cant divide something by 0. What script can I insert into this to make sure this message doesnt keep coming up?

TOPICS
How to, JavaScript

Views

431

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Adobe Community Professional , Jun 28, 2021 Jun 28, 2021
You can format "BMI" as number with 2 decimal under format tab, and try this code,put it into 'Custom calculation': var w = this.getField("Weight"); var h = this.getField("Height"); if(isNaN(w.value) || isNaN(h.value) || w.value == 0 || h.value == 0) event.value = ""; else event.value = w.value/(h.value/100*h.value/100);

Likes

8 Replies 8
Jun 25, 2021 Jun 25, 2021

Copied

Check for 0 in your calculation and set field empty or 0 if it's true, something like this:

if(this.getField("field").value == 0) event.value = "";

else //calculation goes here

of course this is just basic way to do it, it would be helpful if you posted your actual script.

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Engaged ,
Jun 25, 2021 Jun 25, 2021

Copied

The result can be 0, but 0/0=NaN and 1/0=Infinity, so write instead:

``````if(!isFinite(this.getField("field").value)) event.value = "";
else //calculation goes here``````

@+

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Jun 28, 2021 Jun 28, 2021

Copied

This is what I have inserted into both the simplified field notion and custom calculation script but have not had any luck with it calcuating.

if(!isFinite(this.getField("field").value)) event.value = "";
else //Weight/(Height/100*Height/100)

I have tried both of the above scripts.

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 28, 2021 Jun 28, 2021

Copied

You can't use the scripts in the simplified field notion.

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 28, 2021 Jun 28, 2021

Copied

Field name "field" is just example you need to input your field name,also whats are Weight and Height,field names or variables? What are names of two fields you try to calculate and do you use any formats in them?

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Jun 28, 2021 Jun 28, 2021

Copied

Hi Nesa the field names are 'Height' and 'Weight'. The field name I want the calculation in is 'BMI'.

No formats in height and weight  however I would like to format the BMI to 2 decimal places.

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 28, 2021 Jun 28, 2021

Copied

You can format "BMI" as number with 2 decimal under format tab, and try this code,put it into 'Custom calculation':

var w = this.getField("Weight");
var h = this.getField("Height");
if(isNaN(w.value) || isNaN(h.value) || w.value == 0 || h.value == 0) event.value = "";
else event.value = w.value/(h.value/100*h.value/100);

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Jun 29, 2021 Jun 29, 2021

Copied

LATEST

Hi Nesa,

This works perfectly and Ive been able to adjust it for my other calulations.

Thank you very much!!

Likes

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Resources