Copy link to clipboard
Copied
I hope I've posted this in the right place, I'm working on a form in Adobe Acrobat 9. I have a combo box in a form, with Low, Medium, High and No Action Required as the options. What I would like to do is change the colour of the field (either text or background) based on the selection such as
Low - Green
Medium - Orange
High - Red
No Action Required - no change.
Can this be done?
If you mean that you want to change the background color of the combo box, you can use the following custom validate script:
// Custom Validate script for text field
switch (event.value) {
case "Low" :
event.target.fillColor = color.green;
break;
case "Medium" :
event.target.fillColor = ["RGB", 1, .33, 0];
break;
case "High" :
event.target.fillColor = color.red;
break;
case "No Action Required" :
event.target.fillColor = color.white;
break;
}
Copy link to clipboard
Copied
If you mean that you want to change the background color of the combo box, you can use the following custom validate script:
// Custom Validate script for text field
switch (event.value) {
case "Low" :
event.target.fillColor = color.green;
break;
case "Medium" :
event.target.fillColor = ["RGB", 1, .33, 0];
break;
case "High" :
event.target.fillColor = color.red;
break;
case "No Action Required" :
event.target.fillColor = color.white;
break;
}
Copy link to clipboard
Copied
Thank you so much, it now works perfectly, you've made my day
Copy link to clipboard
Copied
Can I call on your expertise once again?
I now have another field (text) which i need to complete automatically based on the response to the preceding drop down list field for example
When the user selects High, Medium or Low from field A text will appear in field B based on the selection above ie Selecting High in field A will auto populate Field B with the following text, "his is serious and must receive urgent attention" and the text will change when selecting Medium or Low.
Copy link to clipboard
Copied
At the beginning of the script, add the following line of code:
var f1 = getField("Field B");
but replace "Field B" with the actual name of the text field. Then, just before each break statement, add a line like this:
f1.value = "his is serious and must receive urgent attention";
but change the text according to which item is selected.
Copy link to clipboard
Copied
Thanks George, I'd just posted my query when your response came through.
I've tried your code but couldn't get it to work, to be honest I don't really know what I'm doing, it's a bit like giving a monkey a shotgun.
Do I add it to the other code you gave me last week or does it goes somewhere else? Sorry to be a pain,
Copy link to clipboard
Copied
Yes, alter the previous code as I described. If it doesn't work, post your new script here so I know what you've changed it to.
Copy link to clipboard
Copied
Thank you so much George, that is brilliant.
Copy link to clipboard
Copied
Hi, I am hoping you can help me. Your code worked perfectly! The only problem is, I am trying to change the RGB to colors that match my pdf. Your example RGB works great, however when I insert my RGB it doesn't work at all and I can't figure out why.
Here is my code:
// Custom Validate script for text field
switch (event.value) {
case "Yes" :
event.target.fillColor = color.green;
break;
case "No" :
event.target.fillColor = ["RGB", 1, .33, 0];
break;
case "1 x per week" :
event.target.fillColor = ["RGB", 146, 200, 78];
break;
case "select one" :
event.target.fillColor = color.gray;
break;
}
The event.target line in NO is your code and it changes to red. the event.target line in 1x per week is the green color I am using elsewhere in my pdf, but when I select 1 x per week, it goes white. Any ideas?
Copy link to clipboard
Copied
The individual numbers in the array range from 0 to 1, not 0 to 255, so use this instead:
event.target.fillColor = ["RGB", 146/255, 200/255, 78/255];
Find more inspiration, events, and resources on the new Adobe Community
Explore Now