-2

I've been looking all over (various forums and tutorials, etc.) and trying to find something that can work. Couple of things first:

• I'm very new to javascript (and all languages really), but learned a little just for this.

• I'm using these javascripts inside validation, calculation and formatting of form fields inside of Adobe Acrobat.

Here's what I'm trying to do: Create a form where users input certain whole numbers into several fields: FieldA, FieldB, FieldC, FieldD, FieldE, FieldF, FieldG, FieldH, FieldI.

Here's how it goes:

• Fields A, B, C, D, F, G - user inputs whole integer.

• FieldE = (FieldD)/3

• FieldH = (FieldG)/(FieldF)

• FieldI = FieldA+FieldB+FieldC+FieldE+FieldH

I'm having trouble with displaying/calculating "0" and "NaN". Instead of dealing with the headache trying to explain to several users what NaN is and why a "0" is there, it's easier to have them not displayed (hidden). On the user end, they won't care if there is no info displayed in any given form field, as long as there aren't a bunch of "0"s or "NaN"s littered throughout the forms. So, the simple solution is: How do I write code to not only detect 0, null, and/or NaN ... but also ... display nothing in any given form field, in these cases. If there is a whole number (in some cases Math.floor implemented for a very specific purpose), then display it.

So, I'm looking for a solution to:

• Keep a form field empty, when 0, Nan, or null is the case.

• Disregard these things in calculations, when this is the case.

• Any actual whole number interger is the only thing to display (even if it is a negative).

Any suggestions?

UPDATE 6/10/2015: This is how I wrote the code.... what am I doing wrong?

{
If ("FieldE" != null && !isNaN("FieldE") &&"FieldE" != 0)
    {
    //calculate for FieldE
    }
else
    {
    // set FieldE = ""
    {
}
Steven L
  • 19
  • 1
  • 3

1 Answers1

1

for the case of:

FieldE = (FieldD)/3

if(FieldE != null && !isNaN(FieldE) && FieldE != 0) {
    //set field value to FieldE
} else {
    //set field value to ""
}

I'm not entirely sure what you're referring to about the "actual whole numbers" part...

  • Apologies about the "actual whole numbers" business. I will clarify. This is in reference to the fact that users will sometimes not populate all fields and so, some fields will be left empty by the user. Thus, "actual whole numbers" means, the field will have an actual number (instead of just being empty) input by the user or automatically calculated and this number will be a whole number, because on all fields, I'm working with math.floor for rounding down with decimals to ensure there are no decimals. – Steven L Feb 05 '15 at 01:35
  • Thanks for the code, btw. It's really appreciated. I'll play with it and see what I can do with it. – Steven L Feb 05 '15 at 01:42