Highlighted

Getting a value from a list box

Community Beginner ,
Sep 04, 2020

Copy link to clipboard

Copied

Everyone,

  I have created a list box that has 5 entries.  What I would like to understand is how do I get the value which the user selects.  I.E. in the list box, entry 3 has "Other".  For the Mouse Up event of the list box, I want to see if the user has selected "Other".  If they did, then I will unprotect another field and it becomes a requred entry.  If they select something else, then I will set it to protected.

  I am sure it is getfield, but unsure of how to structure it.  Can someone direct me on doing this?  Thanx.

 

Jerry

Adobe Community Professional
Correct answer by ls_rbls | Adobe Community Professional

I made a mistake in my prior reply.

 

I was using a combox, not a listbox.

 

The listboxes don't have a an option for custom calculation script. I tested the script now in a listbox and it works fine. 

 

Just don't use it as a mouse-up action. 

 

Do the following:

 

  • Go to the options tab, and make sure that you tick the option "Commit selected value immediately
  • Make sure that you also have an empty string entry in the listed options and select it before you close the Properties dialogue... this is key if you're gonna use reset the form. this.resetForm method will reset that field to whatever the defaulted value is.
  • Last, go to the "Selection Chnage" tab and select "Execute this script" radio button. Put the scipt in that section.

 

This is the script I'm using on my end (and is working):

 

if (event.value == "Other") {
this.getField("txtOther").readonly = false;
this.getField("txtOther").display = display.visible;
this.getField("txtOther").required = true;
} else {
this.resetForm(["txtOther"])
this.getField("txtOther").display = display.hidden;
this.getField("txtOther").required = false;
this.getField("txtOther").readonly = true;
 }
TOPICS
Comment review and collaborate PDF, Create PDFs, Edit and convert PDFs, General troubleshooting, How to, PDF forms, Standards and accessibility

Views

60

Likes

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

Getting a value from a list box

Community Beginner ,
Sep 04, 2020

Copy link to clipboard

Copied

Everyone,

  I have created a list box that has 5 entries.  What I would like to understand is how do I get the value which the user selects.  I.E. in the list box, entry 3 has "Other".  For the Mouse Up event of the list box, I want to see if the user has selected "Other".  If they did, then I will unprotect another field and it becomes a requred entry.  If they select something else, then I will set it to protected.

  I am sure it is getfield, but unsure of how to structure it.  Can someone direct me on doing this?  Thanx.

 

Jerry

Adobe Community Professional
Correct answer by ls_rbls | Adobe Community Professional

I made a mistake in my prior reply.

 

I was using a combox, not a listbox.

 

The listboxes don't have a an option for custom calculation script. I tested the script now in a listbox and it works fine. 

 

Just don't use it as a mouse-up action. 

 

Do the following:

 

  • Go to the options tab, and make sure that you tick the option "Commit selected value immediately
  • Make sure that you also have an empty string entry in the listed options and select it before you close the Properties dialogue... this is key if you're gonna use reset the form. this.resetForm method will reset that field to whatever the defaulted value is.
  • Last, go to the "Selection Chnage" tab and select "Execute this script" radio button. Put the scipt in that section.

 

This is the script I'm using on my end (and is working):

 

if (event.value == "Other") {
this.getField("txtOther").readonly = false;
this.getField("txtOther").display = display.visible;
this.getField("txtOther").required = true;
} else {
this.resetForm(["txtOther"])
this.getField("txtOther").display = display.hidden;
this.getField("txtOther").required = false;
this.getField("txtOther").readonly = true;
 }
TOPICS
Comment review and collaborate PDF, Create PDFs, Edit and convert PDFs, General troubleshooting, How to, PDF forms, Standards and accessibility

Views

61

Likes

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
Sep 04, 2020 0
Adobe Community Professional ,
Sep 04, 2020

Copy link to clipboard

Copied

I think a mouse-up action is not essentially necessary since you can run a script for this purpose as a custom calculation script. 

 

You can run this code directly in the listbox's as custom calculation script.

 

if (event.value =="Other") {

this.getField("myOtherField").readonly = false;
this.getField("myOtherField").required = true;

} else {

this.getField("myOtherField").readonly = true;

} 


 

 

Likes

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
Reply
Loading...
Sep 04, 2020 0
Community Beginner ,
Sep 04, 2020

Copy link to clipboard

Copied

I moved the code over to a Custom Script and does not work.  If I put an "==" in the script and have it in the Mouse Up event, it loops and does not check.  This is the code I have in Custom Edit.  Can you let me know what is wrong?  Thanx.

 

if (event.target.value = "Other")
{
this.getField("txtOther").readonly = false;
this.getField("txtOther").display = display.visible;
this.getField("txtOther").required = true;
}
else
{
this.resetForm(["txtOther"])
this.getField("txtOther").display = display.hidden;
this.getField("txtOther").required = false;
this.getField("txtOther").readonly = true;
}

Likes

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
Reply
Loading...
Sep 04, 2020 0
Adobe Community Professional ,
Sep 04, 2020

Copy link to clipboard

Copied

You moved the script to where? 

 

Are you trying to run the script as a mouse-up action in the listbox field?

Likes

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
Reply
Loading...
Sep 04, 2020 0
Community Beginner ,
Sep 04, 2020

Copy link to clipboard

Copied

I moved it to the custom calculation script for this field.  I removed the Javascript from the Mouse up Action.  I do not have anything under Mouse Action now.

Likes

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
Reply
Loading...
Sep 04, 2020 0
Engaged ,
Sep 04, 2020

Copy link to clipboard

Copied

Try changing first line from this if (event.target.value = "Other") to this if (event.value == "Other")

Likes

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
Reply
Loading...
Sep 04, 2020 0
Adobe Community Professional ,
Sep 04, 2020

Copy link to clipboard

Copied

I made a mistake in my prior reply.

 

I was using a combox, not a listbox.

 

The listboxes don't have a an option for custom calculation script. I tested the script now in a listbox and it works fine. 

 

Just don't use it as a mouse-up action. 

 

Do the following:

 

  • Go to the options tab, and make sure that you tick the option "Commit selected value immediately
  • Make sure that you also have an empty string entry in the listed options and select it before you close the Properties dialogue... this is key if you're gonna use reset the form. this.resetForm method will reset that field to whatever the defaulted value is.
  • Last, go to the "Selection Chnage" tab and select "Execute this script" radio button. Put the scipt in that section.

 

This is the script I'm using on my end (and is working):

 

if (event.value == "Other") {
this.getField("txtOther").readonly = false;
this.getField("txtOther").display = display.visible;
this.getField("txtOther").required = true;
} else {
this.resetForm(["txtOther"])
this.getField("txtOther").display = display.hidden;
this.getField("txtOther").required = false;
this.getField("txtOther").readonly = true;
 }

Likes

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
Reply
Loading...
Sep 04, 2020 0
Community Beginner ,
Sep 04, 2020

Copy link to clipboard

Copied

Works like a charm now.  I thank you very much!  Have a great weekend.

Jerry

Likes

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
Reply
Loading...
Sep 04, 2020 1
Adobe Community Professional ,
Sep 04, 2020

Copy link to clipboard

Copied

Likes

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
Reply
Loading...
Sep 04, 2020 1