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

Getting a value from a list box

Explorer ,
Sep 04, 2020 Sep 04, 2020

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

TOPICS
Create PDFs , Edit and convert PDFs , General troubleshooting , How to , PDF forms , Standards and accessibility
2.1K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Sep 04, 2020 Sep 04, 2020

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

View solution in original post

Translate
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 ,
Sep 04, 2020 Sep 04, 2020

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;

} 


 

 

Translate
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
Explorer ,
Sep 04, 2020 Sep 04, 2020

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

Translate
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 ,
Sep 04, 2020 Sep 04, 2020

You moved the script to where? 

 

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

Translate
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
Explorer ,
Sep 04, 2020 Sep 04, 2020

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.

Translate
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 ,
Sep 04, 2020 Sep 04, 2020

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

Translate
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 ,
Sep 04, 2020 Sep 04, 2020

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;
 }
Translate
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
Explorer ,
Sep 04, 2020 Sep 04, 2020

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

Jerry

Translate
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 ,
Sep 04, 2020 Sep 04, 2020
LATEST

You can find out everything you need to know about list programming here:

https://acrobatusers.com/tutorials/change_another_field/

https://acrobatusers.com/tutorials/list_and_combo_in_lc/

https://acrobatusers.com/tutorials/js_list_combo_livecycle/

https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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