toggle fillcolour onmouseup

Explorer ,
Jul 10, 2019 Jul 10, 2019

Copy link to clipboard

Copied

Hello all,

I'm trying something very simple (at least, it seem like it should be simple!) but I can't seem to get it to work.

I'm running Pro DC.

I have a form on a pdf with the file name "front.jpg", which contains ten rows of ten square text fields (100 in total). They are labelled Front_A1, Front_A2, Front_A3...Front_A10, then Front_B1, Front_B2, Front_B3...Front_B10etc, up to Front_J10.

They are all set with the fillcolor to white (from the colorpicker wheel...). I need them to change their background color to black when the user clicks into the field. If the user then clicks in the field a second time, I want the background colour to return to white.

There is also a second pdf that is attached to the first, entitled back.pdf. contains 100 identical fields, but the horizontal order is reversed, so they go from Front_A10 down to Front_A1, as you read from left to right, and so on down the page.

Then I want to set up a button on the page, that will do the following actions:

1) Check the fillcolor of each field on front.pdf, and of it is white, make the corresponding field on back.pdf black, and if it is black, make the corresponding field on back.pdf, white.

Is that feasible?

I'm afraid I haven't got very far with this, and any spoonfed advice for a novice coder is very much appreciated in the simplest terms possible. (Assume I know nothing and you won't be far from the truth...)

Many thanks in advance for your time, and for your willingness to share your knowledge.

NathanG

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

197

Likes

translate

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
Adobe Community Professional ,
Jul 10, 2019 Jul 10, 2019

Copy link to clipboard

Copied

For the first one, you could set the On Focus JavaScript for the field to the following:

// On Focus script for text field

event.target.fillColor = color.equal(event.target.fillColor, color.black) ? color.white : color.black;

An English translation could be: If the background color of the field that this script is attached to is black, set it to white, otherwise set it to black.

For #2, exactly how is the second form attached to the first?

Likes

translate

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 ,
Jul 11, 2019 Jul 11, 2019

Copy link to clipboard

Copied

George, you are utterly brilliant, and that works like a charm. Thank you so much for your time. Of course, your answer has spawned a couple of questions, so if you can spare me a few more mins, I'd love to know if this is something that can be extended to cycle around three (or more) colours in sequence—so: if fillColor  is black, set it to red, if red, set it to white, if white, set it to black etc...—or would that require a completely different set of instructions. I'm not familiar with the syntax you have given me, (although I feel I should be, as it works like a charm to do what I wanted with two colours!) so I'm not sure how I should customise, (except of course to toggle between two different colours!).

I was trying to go down the if/else if road, and I had this script, which although didn't throw back any errors from the console, didn't actually do anything when I applied it in practice:

if (event.target.fillColor == color.white){

event.target.fillColor = color.black;

}

else{

if (event.target.fillColor == color.black){

event.target.fillColor = color.white;

}

}

And why it wouldn't work has me stumped, but then, I have no training or background in this, and sincerely wish I did!

As for your question, the pdf entitled "back.pdf" is an attachment to the doc called "front.pdf". I clicked on paper clip on the left to open the attachments pane, then on the paperclip with the plus sign, to add an attachment, then browsed to the "back.pdf" file, and clicked Open.

When I add the "master" script to run from the button on the page, would I have to add a piece of comparison code for each and every pair of fields on the two forms? Or is there a way to do this using an array that contains the names of all the ones on the front.pdf, and I guess another array containing all of the names of the fields on the back, or maybe it might be better for me to have all of the fields on both forms have the same names, so that I can use the same array? I'm peeing in the wind, aren't I? I'll leave it with you to advise, if you can, and don't mind doing so, and I shall sit tight and wait to see what greater knowledge than my own can suggest.

Thanks so much once again, and to anyone else who may stop by and offer help. It will all be greatly appreciated.

Best wishes

NathanG

Likes

translate

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
New Here ,
Jul 19, 2019 Jul 19, 2019

Copy link to clipboard

Copied

I agree

Likes

translate

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