Skip to main content
Participating Frequently
May 19, 2020
Question

Button fill color using popupmenu javascript

  • May 19, 2020
  • 2 replies
  • 594 views

Hi - I have a button on a form which will change color based on a selection from a pop up menu activated by clicking the button.  So, click the button, select one of the 5 options and depending on the option selected the entire button will fill with a set color.

 

I have been able to create the pop up menu as I need it, but I cannot get the resulting action (color change) to work.  New to this so would appreciate your help getting the final piece to work.  Thanks.

 

var c = {
'Home':['1,0,0'],
'Motor':['0,176/255,80/255'],
'Marine':['84/255,141/255,212/255'],
'Commercial':['246/255,132/255,38/255'],
'Home Essentials':['1,128/255,1'],
}

var n = new Array('Type of loss:');
for (var i in c) n.push(i);

var result = app.popUpMenu(n);
if (result) {
this.fillColor = ["RGB",c[result]];
}

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
May 20, 2020

Do you need the menu to be two levels deep?

This small change will create a menu with one level.

 

var c = {
'Home':['1,0,0'],
'Motor':['0,176/255,80/255'],
'Marine':['84/255,141/255,212/255'],
'Commercial':['246/255,132/255,38/255'],
'Home Essentials':['1,128/255,1'],
}

var n = new Array();
for (var i in c) n.push(i);

var result = app.popUpMenu.apply(app,n);
if (result) {
this.fillColor = ["RGB",c[result]];
}

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
May 21, 2020

Thank you Thom, i was thinking of that change too.

try67
Community Expert
Community Expert
May 19, 2020

There are several issues with your code... Use this one instead:

 

var c = {
'Home':["RGB", 1,0,0],
'Motor':["RGB", 0,176/255,80/255],
'Marine':["RGB", 84/255,141/255,212/255],
'Commercial':["RGB", 246/255,132/255,38/255],
'Home Essentials':["RGB", 1,128/255,1],
}

var n = new Array('Type of loss:');
for (var i in c) n.push(i);

var result = app.popUpMenu(n);
if (result) {
	event.target.fillColor = c[result];
}
Participating Frequently
May 19, 2020

This is very helpful.  Thanks so much for following me to this post!