Highlighted

## Hide a text field and set the value to zero when another field is filled.

Community Beginner ,
Aug 12, 2020

Copied

Hi ledgehammers, I'm trying to solve a problem I've been locking horns with.

In reality, there are a larger number of fields but for the purposes of this example, lets say I have 3 fields - A (editable), B (read only) and Total (read only).

Field A is blank and field B has a value of 200. The Total field uses the sum calculation (in Properties) to show the combined total of both fields which, at this point, is obviously 200.

The goal is for a user to enter a figure into field A which sets field B to a value of zero and hides it. Since the Total field is just a sum of all existing field values, the change should be reflected automatically.

Additionally, if the user removes their entered figure from field A, field B should reset to a value of 200.

Could I get some assistance from an incredibly generous and intelligent person?

Participant
| Participant

If you still need this check this video  and if it is what you need send me PM and Il help you (for a fee of course).

Topics

PDF forms

Views

194

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

## Hide a text field and set the value to zero when another field is filled.

Community Beginner ,
Aug 12, 2020

Copied

Hi ledgehammers, I'm trying to solve a problem I've been locking horns with.

In reality, there are a larger number of fields but for the purposes of this example, lets say I have 3 fields - A (editable), B (read only) and Total (read only).

Field A is blank and field B has a value of 200. The Total field uses the sum calculation (in Properties) to show the combined total of both fields which, at this point, is obviously 200.

The goal is for a user to enter a figure into field A which sets field B to a value of zero and hides it. Since the Total field is just a sum of all existing field values, the change should be reflected automatically.

Additionally, if the user removes their entered figure from field A, field B should reset to a value of 200.

Could I get some assistance from an incredibly generous and intelligent person?

Participant
| Participant

If you still need this check this video  and if it is what you need send me PM and Il help you (for a fee of course).

Topics

PDF forms

Views

195

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
Aug 12, 2020 0
18 Replies 18
Participant ,
Aug 12, 2020

Copied

Hi, I belive this will do what you asked for, use it as "Custom Calculation Script" of "A" field, and also in "Total" field use "Simplified Field Notation" under calculate tab like this A+B.

var a = this.getField("B");
if(event.value != ""){
a.value = 0
a.display = display.hidden;
}else if(event.value == ""){
a.value = 200
a.display = display.visible;
}

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
Aug 12, 2020 1
Community Beginner ,
Aug 13, 2020

Copied

Hi NesaNurani, thanks so much for helping me with this.

Unfortunately, the person I've created the form for his since changed the desired outcome a little. I say a little but I believe it may make it much harder to achieve. I've edited the original text to the following:

In reality, there are a larger number of fields but for the purposes of this example, lets say I have 2 fields and one text object - field A (editable), text object B and Total (read only).

Field A is blank and text object B has a value of 200. The Total field uses the sum calculation (in Properties) to show the total of all text objects which, given that we only have one text object in this example, is set with a default value of 200.

The goal is for a user to enter a figure into field A which changes text object B style to strikethrough and discounts the value in the Total field. Since the Total field is already set at value, the change should be reflected automatically if the value in field A is deleted.

Additionally, if the user removes their entered figure from field A, text object B should reset to not having the strikethrough.

Again, thank you. I hope you can continue to assist!

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
Aug 13, 2020 0
Community Beginner ,
Aug 13, 2020

Copied

Hi NesaNurani, thanks so much for helping me with this.

Unfortunately, the person I've created the form for his since changed the desired outcome a little. I say a little but I believe it may make it much harder to achieve. I've edited the original text to the following:

In reality, there are a larger number of fields but for the purposes of this example, lets say I have 2 fields and one text object - field A (editable), text object B and Total (read only).

Field A is blank and text object B has a value of 200. The Total field uses the sum calculation (in Properties) to show the total of all text objects which, given that we only have one text object in this example, is set with a default value of 200.

The goal is for a user to enter a figure into field A which changes text object B style to strikethrough and discounts the value in the Total field. Since the Total field is already set at value, the change should be reflected automatically if the value in field A is deleted.

Additionally, if the user removes their entered figure from field A, text object B should reset to not having the strikethrough.

Again, thank you. I hope you can continue to assist!

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
Aug 13, 2020 0
Contributor ,
Aug 13, 2020

Copied

I belive on this link it says you can't use strikethrough  in javascript.

But in the book that I have ( the one which is obviously full of mistakes)  there is code for strikethrough but i wasn't able to use it in a script.

It would be nice if someone with more knowledge answers is it or isn't possible to use it in javascript.

Here is example from the "Book" Enhancing Adobe Acrobat DC Forms with JavaScript by Jennifer Harder

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
Aug 13, 2020 0
Aug 13, 2020

Copied

There is no such field property.  You cann't just make things up. Check the Acrobat JavaScript Reference before you post nonsense like this.

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
Aug 13, 2020 0
Aug 13, 2020

Copied

Refer to these articles for basic scripting around these issues.

https://www.pdfscripting.com/public/How-to-set-000-value-to-blank.cfm

https://www.pdfscripting.com/public/Hiding-and-Showing-Form-Fields.cfm?sd=40

Now, what kind of animal is "text object B"?  is it a text anotation? a form field? page text?  How the strikethough appearance is created is different for each case.

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
Aug 13, 2020 0
Contributor ,
Aug 13, 2020

Copied

I'm not making things up it's in the book I paid for 30\$ ( it's the same book where there were SFN and time calculation if you remember?) the book is from 2017.

here is the page from the book about Various Types of Formatting with JavaScript

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
Aug 13, 2020 0
Explorer ,
Aug 13, 2020

Copied

I also have that book I bought it with the advice of Jean-Claude_Tremblay in this forum.

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
Aug 13, 2020 0
Aug 13, 2020

Copied

It doesn't say what "event.target" represents? This is a very odd way to present code. What does it say "event.target" is?

But the fact is that there are only two common scripting contexts (field events and document events) that return event.target, and it is either a document object or  a field object.  The properties listed do not  belong to either of these objects.

However, they are members of the Spans object.

So far it sounds like this book is a load of crap. If you want to learn about scripting, read the Acrobat documents on it and read the articles on this site:

https://www.pdfscripting.com/public/main.cfm

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
Aug 13, 2020 0
Aug 13, 2020

Copied

I think I see where the mixup may have happened. The properties listed in the book are valid on event.target in an InDesign script. They have nothing to do with Acrobat scripting. Again, what is the context for the code shown in the book?

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
Aug 13, 2020 0
Contributor ,
Aug 13, 2020

Copied

Here are few pages from that chapter about formatting.

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
Aug 13, 2020 0
Aug 13, 2020

Copied

Wow, that's incredibly vague.

Here's the operative sentence:

"Some other formatting you can use with some PDF tools, but not form fields, are the following:"

This literally makes no sense, what PDF tools is she talking about. Certainly nothing to do with Acrobat. I'd mark this page with a big red X, and the note, Not Acrobat Scripting.

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
Aug 13, 2020 0
Community Beginner ,
Aug 15, 2020

Copied

Hi Thom, thanks for taking a look at the problem!

Excuse my knowledge of element definitions in Acrobat; 'text object' is what you would understand to be page text, yes.

Below is an image of part of what I'm working on which I really should've provided initially:

The checkboxes are intended, when checked, to add the corresponding figure in the farthest right column (page text B) to the subtotal. The next column to the right is field A. When a user enters a lower figure here, the desired outcome is for the new amount to be added to the subtotal instead, while the figure shown to the right of it (page text B) inherits a strikethrough. In the image provided, let's imagine all of the checkboxes have been selected which has resulted in the subtotal showing the sum of all standard prices.

Thanks again for looking into this, any help is appreciated and my apologies for causing any confusion or conflict!

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
Aug 15, 2020 0
Participant ,
Aug 15, 2020

Copied

If you still need this check this video  and if it is what you need send me PM and Il help you (for a fee of course).

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
Aug 15, 2020 1
Community Beginner ,
Aug 16, 2020

Copied

Hey NesaNurani, thanks so much for the offer but it's really just the strikethrough part I can't wrap my head around. There's no rush on this since I'm not charging to make it for the person intending to use it and I can get everything working aside from just that one element. I'll do some more investigating but if I can't figure it out, I'll come back 🙂

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
Aug 16, 2020 0
Participant ,
Aug 16, 2020

Copied

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
Aug 16, 2020 0
Aug 16, 2020

Copied

That video is quite nice 🙂  Looks like you created the solution.  Unfortunately there are several versions of the Acrobat JavaScript Reference. The latest few are on line, so there are not page numbers. Did you do this using a Rich Text on a field?

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
Aug 16, 2020 0
LATEST
Aug 16, 2020

Copied

Black_Marketing -

If the "Amount" column is page text, and not a field value, then you would use a "StrikeThorugh" annotation to create the effect, hiding/showing it as necessary. However, if the Amount column is form fields, then you would create the effect using rich text. Look up the "Spans" object in the Acrobat JavaScript Reference. Either case is quite simple to implement, but I think that using form fields is better because it makes it easier to update the Amount values.

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
Aug 16, 2020 0