• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Button fill color using popupmenu javascript

Community Beginner ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

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]];
}

TOPICS
Acrobat SDK and JavaScript

Views

420

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 Expert ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

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];
}

Votes

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 ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

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

Votes

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 Expert ,
May 20, 2020 May 20, 2020

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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 ,
May 21, 2020 May 21, 2020

Copy link to clipboard

Copied

LATEST

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

Votes

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