Skip to main content
Inspiring
November 18, 2020
Question

Dropdown list selection question

  • November 18, 2020
  • 2 replies
  • 423 views

Hello,

 

I have a dropdown list with values

-- (first value)

01 (second value)

02 

03

 

And a textfield. This text field will have a string - 01 for example.

I want the user to not be able to select the value which is in the textfield, from the dropdown list. I've tried this code but it's not working as expected -I have to click multiple times there to work-- added it in the Mouse Down event for the dropdown list

 

 

if (this.getField("Dropdown").valueAsString==this.getField("Textfield").value)
{
app.alert("this value can't be selected",1);
this.getField("Dropdown").currentValueIndices=0;
}

 

 

Can you please give me an idea? Thank you.

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
November 18, 2020

Add this script to the Custom Validation script on the dropdown

 

 

event.rc = event.value != this.getField("TextField").valueAsString;
if(!event.rc)
    app.alert("this value can't be selected",1);

 

 

The validation script is the correct place to "validate" a selection. The "event.rc" property determines whether or not the selected value is accepted. The "validation" event occurs before the selected value is actually committed, so the only way to access the current selection is though the event object. 

 

You can read more about dropdown fields here:

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

 

And validation scripts here:

https://www.pdfscripting.com/public/Form-Data-Validation.cfm

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
oanassAuthor
Inspiring
November 18, 2020

Thank you very much for the code and for the links!

oanassAuthor
Inspiring
November 18, 2020

I think the code is ok but I'm not placing it in the right place.