Copy link to clipboard
Copied
Hello I am new to adobe acrobat. I have a form with two radio button selection. If a customer selects, "Yes" radio button, a text field with "Yes" color background changes into Green, if selected Radio button, "No", textfield,"No" color background color changes to "Red".
Thank You
Pet
As the custom calculation script for "MDC_Yes" enter:
event.target.fillColor = this.getField("MDC").valueAsString=="Yes" ? color.green : color.transparent;
And for the "MDC_No" field enter:
event.target.fillColor = this.getField("MDC").valueAsString=="No" ? color.red : color.transparent;
I just noticed that you tried to employ Try67's code and then you went and tried my variation.
Before you continue with troubleshooting you have to decide which code to test with.
It if helps, my code is meant to be run directly from the radio buttons as a Mouse-Up action: MDC_Yes radio button in my example has export value of "Choice1" and MDC_No radio button. has export value of "Choice2".
That said, are you getting the same error with both codes, even if the radio buttons are set as mu
...ls_rbls & Try67,
Thank you for your help. Both codes works fine. I found out that I made a text field name errors. I also delete the textfield with total exhaust cfm. The code works fine both of yours. I appreciate your follow ups and continuous help.
Thank you, Thank you, Thank you.
Pet
Copy link to clipboard
Copied
As the custom calculation script for "MDC_Yes" enter:
event.target.fillColor = this.getField("MDC").valueAsString=="Yes" ? color.green : color.transparent;
And for the "MDC_No" field enter:
event.target.fillColor = this.getField("MDC").valueAsString=="No" ? color.red : color.transparent;
Copy link to clipboard
Copied
Thank you tey67,
I copy paste your code, however, the textfield's backgroung color isn't changing. Am I missing anything?
Thank you
Pet
Copy link to clipboard
Copied
Make sure to disable the Fields Highlighting option.
Copy link to clipboard
Copied
This also worked for me:
Create the pair of Radio Buttons with the same name, but different export values fro each. For example, "Choice1" and "Choice2" respectively.
In the radio button with Choice1 export value using this script:
this.getField("MDC_Yes").value = "Yes"
this.getField("MDC_Yes").fillColor = color.green;
this.getField("MDC_Yes").readonly = true;
this.getField("MDC_No").value = "";
this.getField("MDC_No").fillColor = color.transparent;
this.getField("MDC_No").readonly = true;
And in the radio button with "Choice2" export value this script:
this.getField("MDC_No").value = "No"
this.getField("MDC_No").fillColor = color.red;
this.getField("MDC_No").readonly = true;
this.getField("MDC_Yes").value = "";
this.getField("MDC_Yes").fillColor = color.transparent;
this.getField("MDC_Yes").readonly = true;
Copy link to clipboard
Copied
Thank you ls_rbls,
So when I applied the code under each javascript:
The "Yes" but didnt work.
The "No" but woks howeve when I select the "Yes" button the Red color remains. I coudn't figure out how. Any ideas. Thank you.
Copy link to clipboard
Copied
There are many things that can go wrong with scripts, even very simple scripts. For example, names must be verbatim. And programming syntax is picky, each bracket, quote, etc. must be in exactly the correct location.
So a good place to start figuring out what went wrong is to look in the JavaScript Console Window. This is where Acrobat reports errors. You can also use it to test code, so you don't have this exact issue.
You'll find a video tutorial on the console here:
https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro
Check the console and let us know if anything is reported. If not, then try running each of the code block in the console to see what happens.
Copy link to clipboard
Copied
did you name both radio buttons with the same field name?
If yes, did you change the export values on each. When you set a pair of radio buttons as mutually exclusive they must have different export values to act as if they're independent from each other. Otherwise, they will be selected in unison.
Also, are you sure you're using radio buttons and not checkboxes?
Copy link to clipboard
Copied
ls_rbls,
I believe I did. I have attached snapshot of my form for Choice1
2. Option: exort value;
2. Action javascript
3, Code;
I hope, you can see what I have done.
Thank you
Copy link to clipboard
Copied
Check the JS Console for errors (Ctrl+J) after clicking either one of those fields.
Also, you should use Mouse Up, not Mouse Enter.
Copy link to clipboard
Copied
Try67,
I checked the JS console for an error(s). It displays an error that has nothing to do with the radiobutton's function. The "TOTAL_EXHAUST_CFM" adds up the 10 fields and send the result to calculate the "TOTAL_EXHAUST". The radiobuttons (YES & NO) have not calculation. Is it something I miss? See photo.
Copy link to clipboard
Copied
Try this,
1) fix the existing errors so they don't get in the way.
2) One at a time, copy the code for each MouseUp script into the console and run it. See what happens there.
Copy link to clipboard
Copied
In your last screenshot for step 3, see the fourth line of the code used ...look from top to bottom
See the line:
this.getField("MDC_No").value = " ";
The null value is expressed as "".
You have an extra blank space in between the quotes. Remove that blank space. Check the same line in the radio button code with export value of Choice2
Copy link to clipboard
Copied
lr_rbls,
I double checked the space between the "", as you said, I found one from the MDC_Yes. MDC_No has no space. After I removed the space and also check for any other besides that there was none. The code is not working yet. My question is does the code location matters? I entered the code under -> Action tab -> Mouse Enter -> Run a JavaScript.
Thank you.
Copy link to clipboard
Copied
the line
this.getField("MDC_No").value = " ";
literally has no affect on the code working or not working.
If you want to find out what's not working, then follow my suggestion and run the code in the console where you can debug it directly.
Copy link to clipboard
Copied
I am sorry to read that...
The script that I shared with you is working fine on my end.
As you mentioned, the error that you're getting seems to be related to something else.
In my opinion, I think you have other claculated fields that get affected based on the checked or unchecked state of the radio buttons.
I mention the observation about the double space because a calculated field may be expecting "" instead of a double or single space. From the user point of view this is irrelevant in terms of the errors that you may be experiencing.
But in terms of scripting, those calculated fields will not accept anything else if the value of the of the MDC_No field is set with a
blank space by the value provided with the radio.
This is just an observation for caution. Like Thom indicated this may not be related at all with your error.
But in my case, I discovered, for example, that when you use "" to express a null value in the "Send To:" or "From:" portions of an email script it will open your email client by default (in windows MS Outlook will pop up if it is set as default) and those blanks will be empty.
On the other hand, if you use " " with a blank space in that same email script above, it will open the Windows Address book before Outlook is launched because it won't be able to find a recipient named single blank space or double blank space, thus getting an undesired result and unexpected application behavior.
From a cybersecurity point of view, is little things like this that very often become an exploit or better said, it may lead to exploitable backdoors in computer programs.
Just food for thought.
Copy link to clipboard
Copied
Yes, it matters a great deal. As I wrote before, it should be under Mouse Up, not Mouse Enter.
Copy link to clipboard
Copied
ls_rbls,
As you've mensioned, I removed the gap between "" on both MDC_Yes & NO. However, the code is not working. Question to you, does the location of the code matter? I put it under the Action tab - Mounse Enter Run a JavaScript.
Thank you.
Copy link to clipboard
Copied
Why do you complicate this post so much, try67 code above should work fine for you, if it doesn't work then you must be having something else going on in your field or you lack knowledge how to use code in either case, don't make people here guess what it is and just post your file so they can see what is going on.
Copy link to clipboard
Copied
I just noticed that you tried to employ Try67's code and then you went and tried my variation.
Before you continue with troubleshooting you have to decide which code to test with.
It if helps, my code is meant to be run directly from the radio buttons as a Mouse-Up action: MDC_Yes radio button in my example has export value of "Choice1" and MDC_No radio button. has export value of "Choice2".
That said, are you getting the same error with both codes, even if the radio buttons are set as mutually exclusive with different export values each?
As I am running out of ideas., the only thing I can think of is to check the calutaion tab on both text fields "MDC_Yes" and "MDC_No" respectively. If you have any cuctom calculation scripts there you have to remove them to rule out if the problem is related to those custom calculation scripts, or post another screenshot to see what you have there.
I think the radio button part was already answered correctly.
You also need to provide us with what you have running in TOTAL_EXHAUST_CFM" when you say it adds up the 10 fields and send the result to calculate the "TOTAL_EXHAUST".
What code (if any) or calculation method are you using in the "TOTAL_EXHAUST_CFM" and the "TOTAL_EXHAUST" text fields??
Copy link to clipboard
Copied
ls_rbls & Try67,
Thank you for your help. Both codes works fine. I found out that I made a text field name errors. I also delete the textfield with total exhaust cfm. The code works fine both of yours. I appreciate your follow ups and continuous help.
Thank you, Thank you, Thank you.
Pet