Click button once, twice, ... to show different symbols

Community Beginner ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Hello everyone, is it possible to create a button which shows symbol A when being clicked once, symbol B when being clicked twice and symbol C when being clicked for the third time?

I also have some troubles finding the right symbols for my case. I need a checkmark, an exclamation mark and a slash. I thought, maybe it would be the best solution, if I could let show the symbols as pictures.

In conclusion, that would mean: First Click -> Pic 1, Second Click -> Pic 2, Third Click -> Pic 3. The images should appear in the same place so that they are mutually exclusive.

 

I would be very grateful for a helpful answer!
TOPICS
Create PDFs, How to, JavaScript, Rich media and 3D

Views

319

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

correct answers 1 Correct Answer

Adobe Community Professional , Apr 09, 2021 Apr 09, 2021
You can try this code: if(event.target.buttonGetCaption()==""){event.target.buttonSetCaption("✔");event.target.textColor = color.green;}else if(event.target.buttonGetCaption()=="✔") {event.target.buttonSetCaption("!");event.target.textColor = color.red;}else if(event.target.buttonGetCaption()=="!"){event.target.buttonSetCaption("/");event.target.textColor = color.black;}else if(event.target.buttonGetCaption()=="/")event.target.buttonSetCaption("");

Likes

translate

Translate

Translate
Most Valuable Participant ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Search the forum for "tri-state field". This issue was discussed many times in the past, and there are complete code samples on how to do it.

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
Community Beginner ,
Apr 09, 2021 Apr 09, 2021

Copy link to clipboard

Copied

Many thanks for the answer. The tip helped me a lot. I only have one more question: Is it also possible that the field starts empty at first? So, if you haven't clicked anything yet, the button is empty/blank. And only when you click once does a tick appear and so on ... That would be very important for my client. At the moment there is a green checkmark in every field from the start, without anything being clicked. This is the script, I used/copied from another thread: 

 

if(color.equal(event.target.textColor,color.black))
{
event.target.textColor = color.green;
event.target.buttonSetCaption("✔");
}
else if(color.equal(event.target.textColor,color.green))
{
event.target.textColor = color.red;
event.target.buttonSetCaption("!");
}
else
{
event.target.textColor = color.black;
event.target.buttonSetCaption("/");
}

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
Engaged ,
Apr 09, 2021 Apr 09, 2021

Copy link to clipboard

Copied

Where and how do you use that script and what font do you use?

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
Community Beginner ,
Apr 09, 2021 Apr 09, 2021

Copy link to clipboard

Copied

I use the script in Adobe Acrobat for an interactive PDF form. Why is the font relevant? Because of the symbols?

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
Most Valuable Participant ,
Apr 09, 2021 Apr 09, 2021

Copy link to clipboard

Copied

Yes, just clear its label and move the section of the code that sets the tick character to the end, in the final else clause.

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
Community Beginner ,
Apr 09, 2021 Apr 09, 2021

Copy link to clipboard

Copied

Thanks for the answer! I suppose it would be helpful if I understood it. Would it be possible for you to rewrite my script as you mean it. Unfortunately, I have absolutely no idea about it and am still at the very beginning to learn it.

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 ,
Apr 09, 2021 Apr 09, 2021

Copy link to clipboard

Copied

You can try this code:

if(event.target.buttonGetCaption()==""){
event.target.buttonSetCaption("✔");
event.target.textColor = color.green;}
else if(event.target.buttonGetCaption()=="✔") {
event.target.buttonSetCaption("!");
event.target.textColor = color.red;}
else if(event.target.buttonGetCaption()=="!"){
event.target.buttonSetCaption("/");
event.target.textColor = color.black;}
else if(event.target.buttonGetCaption()=="/")
event.target.buttonSetCaption("");

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
Community Beginner ,
Apr 11, 2021 Apr 11, 2021

Copy link to clipboard

Copied

Thanks for your answer! After I've inserted the script, it behaves like a "normal" checkbox: initially empty and when I click on it once, a black checkmark appears. When I click on it again, it's empty again. : / Do you have any other idea what might work or what the problem is?

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 ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

It's for a button not checkbox.

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
Community Beginner ,
Apr 12, 2021 Apr 12, 2021

Copy link to clipboard

Copied

Oh I am sorry! You're right. What a stupid mistake on my part. I have now pasted your script on a button and it works perfectly! Thanks alot!

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
Most Valuable Participant ,
Apr 09, 2021 Apr 09, 2021

Copy link to clipboard

Copied

So is the empty string part of the sequence, or only in the beginning? In other words, what should happen when the button shows "/" and they click it again?

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