These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Force "+" or "-" to show

Duniagdra
Registered: Sep 24 2008
Posts: 140
Answered

I tried searching here and other places, but I'm not finding what I thought I should. Maybe my search criteria is not right.

Anyhow, I'm looking to show a "+" or "-" depending on if the result is positive or negative.

Example:
If result is a bonus 3 then I want it to show as +3, but if it is a penalty (negative) it should show -3. I saw this once some time ago, but now that I need it, I can't find how to do it. Concatenate comes to mind, but I don't remember.

Thanks in advance for any help you offer,
Jim

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

My Product Information:
Acrobat Pro 8.0, Windows
Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi Duniagrdra,

You can use unicode for the + and - signs in fields. Read the JavaScript Corner article at the link below for more info- there is a downloadable PDF with example code as well. You will have to figure out what the unicode is for the symbols- a Google search should work easily for that.

http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/using_unicode_text/

Hope this helps,

Dimitri
www.pdfscripting.com
www.windjack.com
Duniagdra
Registered: Sep 24 2008
Posts: 140
Dimitri wrote:
Hi Duniagrdra,You can use unicode for the + and - signs in fields. Read the JavaScript Corner article at the link below for more info- there is a downloadable PDF with example code as well. You will have to figure out what the unicode is for the symbols- a Google search should work easily for that.

http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/using_unicode_text/

Hope this helps,

Dimitri
www.pdfscripting.com
www.windjack.com
Thanks Dimitri,

This did help, but here is my hack at coding it:
var Mod = Number(this.getField("Ability_STR_ModLevel").value) if(Mod > 0){event.value = "\u002B" + Mod};if(Mod < 0){event.value = "\u002D" + Mod};

While I get no errors, I'm also not getting the +/- to show. I've tried searching syntax and the above layout was what I found, kind of. I'm a top notch hack. What am I missing or is there a better way of doing this?

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Where did you place that code? What field, what event?

George
Duniagdra
Registered: Sep 24 2008
Posts: 140
never mind. found it was actually the "/" that was the issue. I guess for the example in the link you gave me to work they had to add the "/" for the unicode to show. It works great, thanks for the help. This has taken me another great step forward in achieving my goal.

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

Duniagdra
Registered: Sep 24 2008
Posts: 140
Duniagdra wrote:
never mind. found it was actually the "/" that was the issue. I guess for the example in the link you gave me to work they had to add the "/" for the unicode to show. It works great, thanks for the help. This has taken me another great step forward in achieving my goal.
I'm not sure what happened since the code was the same as originally written. I have this as a custom script:
var Mod = Number(this.getField("Ability_STR_ModLevel").value) if(Mod > 0){event.value = "u002B" + Mod};if(Mod < 0){event.value = "u002D" + Mod};

For some reason, at work it was fine. I open it at home and now my result is u002B in stead of +3.

I'm sorry, but I need help again. To answer George's question, the code was originally a custom script in "Field1". I'm not sure what he was asking about what event unless he was referring to the action? If so, it's not used. I was going to try and make it a document level function so I could use it in more than one field, but...

Please tell me what I did wrong?
Jim

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
> ...the code was originally a custom script in "Field1".A custom calculation script?

In any case, you need to escape the "u" with a backslash to indicate a unicode sequence. But you don't even need to do that since the following should work:

var Mod = +getField("Ability_STR_ModLevel").value; if (Mod > 0) {event.value = "+" + Mod};if (Mod < 0) {event.value = "-" + Mod};

George
Duniagdra
Registered: Sep 24 2008
Posts: 140
George_Johnson wrote:
> ...the code was originally a custom script in "Field1".A custom calculation script?

In any case, you need to escape the "u" with a backslash to indicate a unicode sequence. But you don't even need to do that since the following should work:

var Mod = +getField("Ability_STR_ModLevel").value; if (Mod > 0) {event.value = "+" + Mod};if (Mod < 0) {event.value = "-" + Mod};

George
Thanks George,

I pretty much copied the code as I saw it with some mod to fit my need and removing the / had it working the first time I tried it. This does work and I can move on to the next step again.

Did you feel I should not run this as a custom calculation script?

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
> Did you feel I should not run this as a custom calculation script?No, that's fine, it just wasn't clear where you placed the code, which is an important thing to know for those of us who do not have your form in front of us.

If you post again for help with specific code, I would strongly urge you to include exactly where you've placed the code (what field, what event) and include other information such as the names of other fields involved.

BTW, for the code above, is it possible that Mod will ever be zero?

George
Duniagdra
Registered: Sep 24 2008
Posts: 140
George_Johnson wrote:
> Did you feel I should not run this as a custom calculation script?No, that's fine, it just wasn't clear where you placed the code, which is an important thing to know for those of us who do not have your form in front of us.
Okay, cool.

George_Johnson wrote:
If you post again for help with specific code, I would strongly urge you to include exactly where you've placed the code (what field, what event) and include other information such as the names of other fields involved.
I try my best to give as much detail as I can, but determining what's too much and what's too little, I'll try being more specific. May I ask what exactly do you mean by "what event"? Are you referring to event.value and such?

George_Johnson wrote:
BTW, for the code above, is it possible that Mod will ever be zero?
Thanks for pointing out that oversight. I've added this correction and tested it; seems to work.

if(ShowScore == 0){event.value = ShowScore};

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
> May I ask what exactly do you mean by "what event"?
> Are you referring to event.value and such?No. I'm referring to the various events associated with fields, including Calculate, Validate, Keystroke, Format, Mouse Up, Mouse Down, Mouse Enter, Mouse Exit, Blur, and Focus. Then there are the various document events, and events associated with bookmarks, links, etc.

George
Duniagdra
Registered: Sep 24 2008
Posts: 140
Okay, Will do George.

Again, thank you both, George and Dimitri, for your help in this.

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack