• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
Aug 12, 2020 Aug 12, 2020

Copy link to clipboard

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?

TOPICS
PDF forms

Views

3.0K

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Aug 15, 2020 Aug 15, 2020

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).

Votes

Translate

Translate
Community Expert ,
Aug 12, 2020 Aug 12, 2020

Copy link to clipboard

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;
}

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

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!

Votes

Translate

Translate

Report

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

Copy link to clipboard

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!

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

https://community.adobe.com/t5/acrobat/strikethrough-text-field-based-on-radio-button-status-using-j... 

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

Izrezak.PNG

Votes

Translate

Translate

Report

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

Copy link to clipboard

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.

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Please ignore the post from Aism123. That was extremely bad advice.

 

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. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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

Copy link to clipboard

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

Pages from Javascript 2017.jpg

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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

Copy link to clipboard

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?

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Here are few pages from that chapter about formatting.

Votes

Translate

Translate

Report

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

Copy link to clipboard

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. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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

Copy link to clipboard

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

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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

Copy link to clipboard

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:

Screen Shot 2020-08-15 at 10.16.58 pm.png

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!

Votes

Translate

Translate

Report

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

Copy link to clipboard

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).

Votes

Translate

Translate

Report

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

Copy link to clipboard

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 🙂

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Find this "javascript for adobe api reference" page 677. That should help you figure it out. 

Votes

Translate

Translate

Report

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

Copy link to clipboard

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?   

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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