How can I make a decimal field default to a negative dollar amount?

katied4341021 02-08-2016

I am doing a form that basically works like a check book.  I have one column that is ALWAYS going to be a negative dollar amount.  I've figured out how to make the number negative IF the user enters it with a minus sign (ex: -100 would show up as ($-100.00)).

However, I'm wondering if there is a way to get that field to be a negative dollar amount no matter what the user enters? Example: user simply types 100, when they tab out, I want it to automatically change to ($-100.00).

Is this possible?  Thanks in advance.

Mark Solution

Are these answers useful?
Help other community members by marking useful answers as accepted.

Accepted Solutions (0)

Answers (6)

Answers (6)

mattiaswallin 03-08-2016

Yes I suspected you meant it like that but wasn't sure as you wrote "where to put the minus sign".

Anyhow, being in Adobe LiveCycle Designer, there is a thing called the "Script Editor". If you don't have that showing you can find it by navigating from the top most toolbar -> "Window" and click -> "Script Editor". Alternatively press ctrl+shift+f5.

What you want to do is to link your script to a certain the object (field) and then choose what event it will trigger on (I will try to explain a bit easier later). So for your case:

  1. Highlight the field you want the script in (in your case it seems like a decimal field in a table).
  2. Choose the event you want (exit) by opening the dropdown menu in the topleft corner of the script editor and clicking it.
  3. Simply enter the code Magus wrote above in the text area of the editor.

And then you have it!

So the event is just what it sounds like, an event on which you want something to happen. So for your case what will happen is, the user will enter the decimal field, put in some data and then exit. And then the code you have said should be executed upon the exit event will be executed and do what I tried to explain earlier.

It's quite simple when you get the hang of it, I hope this may help you a bit

Regards, Mattias

mattiaswallin 02-08-2016

That is dealt with in the second row of Magus code, if you want to understand it a little bit better I will try to write it in "regular" language:

First he declares a variable named "amount" which is then assigned to take on the mathematical absolute value of what was entered in the field, meaning that no matter if the user enters +6.84, -6.84 or 6.84 what will be stored in the amount variable will always be 6.84 (the magnitude of what was entered). Then in the second row he declares that the value of the field should become MINUS what is stored in the variable amount, so that what finally ends up in the field will always be minus. (In my specific example -6.84)

So what you end up with will ALWAYS be negative

Or do you have a problem with how you will enter the script? Realizing I am maybe misinterpreting your last comment.

Magus069
MVP
02-08-2016

Hi there,

regardless of what the user enters, if you always want to put the number to minus, use the following code on the exit event

Math.abs is a method which returns the absolute value of a number, once this is done, just put a minus sign before the value

Hope this will help

katied4341021 03-08-2016

Your last question is correct - I don't understand how to enter the script.  This stuff is WAY above my head, but I'm the Maker of Forms in the office... I'm trying to make it as easy as I can for myself.