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

Validate Dropdown selections

New Here ,
Jan 20, 2017 Jan 20, 2017

Hey everyone,

 

I am most certain this is a simple if statement, but since my java knowledge is pretty outdated, I need some help. I am creating an interactive pdf and I need to validate the form. I am using dropdown menus for the most part and I need a script to check to see if the default selection is still present. If so, I need a prompt to highlight  the dropdown menu that still has the default value present.  Can anyone help?

 

Thanks!

- G

5.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
Community Expert ,
Jan 20, 2017 Jan 20, 2017

You can use this code to do that:

var f = this.getField("Dropdown1");

if (f.valueAsString==f.defaultValue) {

    app.alert("You must fill in this field before submitting the file.",1);

    f.setFocus();

} else this.mailDoc();

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
New Here ,
Jan 20, 2017 Jan 20, 2017

For some reason, this is not working. I just tested it and left one of the dropdown selections with the default value and no prompt or error code populates. I have attached this code within a button.

Thanks!

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 ,
Jan 20, 2017 Jan 20, 2017

You can't attach PDF files here. You should upload it to a sharing website like Dropbox or Google Drive and then post the link to it.

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
New Here ,
Jan 20, 2017 Jan 20, 2017

I did not attach anything in here. My apologies if I was not clear. I meant to say that I attached your code with the correct name of my dropdown menu within a button and not directly in the dropdown. Sorry if this is unclear.

Thanks!

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 ,
Jan 20, 2017 Jan 20, 2017

So what happens when you click the button, exactly? Are there any error messages in the JS Console (Ctrl+J)?

Can you share the actual file?

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
New Here ,
Jan 20, 2017 Jan 20, 2017

I can not share the actual file (internal use only), nothing happens when I select the button with the code, no error messages or anything.

- G

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 ,
Jan 20, 2017 Jan 20, 2017

Then create a file with just the drop-down field (you can replace the values with dummy ones) and the submit button and share that... Otherwise it's very hard to help you.

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
New Here ,
Jan 20, 2017 Jan 20, 2017

Ok, so I just got it to work! Which is great, thank you! But it doesn't highlight the dropdown that is causing the prompt. I have the java included in the submit but a step before the email submission. Also, how you make the script validate multiple drop down menus or do I have to use a separate line of script to call out each DD?

I have included a sample doc.

dropdown-validation-mockup-interactive.pdf - Google Drive

THANK YOU once again!

- G

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 ,
Jan 21, 2017 Jan 21, 2017

You need to delete the "Submit form" command and leave only the Run a JavaScript command. The script takes care of submitting the form, and will abort it if the field is not filed-in. If you do that you will also see that the script causes that field to become selected, so it's obvious to the user which field is referred to.

Regarding performing this for multiple fields: It can be done using a more generic script.

You would need to set those fields as "required" and then use a script to iterate over all of the fields in the file, checking that the required ones among them are actually filled in. I've posted several codes that do that over the years on these forums. Try searching for "required fields validation" and I'll sure you'll find it.

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
New Here ,
May 05, 2020 May 05, 2020

I am trying to use the script below based on the comments above, but I'm also needing to get it to work for multiple fields. I would like it to work for fields named Facility, Title, Type, Hours, Shift, and Matrix. All are dropdown fields with the default value as a blank spacebar, but I want the users to have to select an actual value in all of those fields before the submit email opens. I'm having trouble finding a script you've done for multiple dropdown fields -- I've found them for blank text fields, but since the dropdown isn't technically blank, that's where I'm struggling. I'm hoping you could point me in the right direction? Sorry, this answer has been the closest I could find, and it's my first time using javascript. 

 

var f = this.getField("Facility");

 

if (f.valueAsString==f.defaultValue) {

 

    app.alert("You must fill in all required fields before submitting the file.",1);

 

    f.setFocus();

 

} else this.mailDoc({

    cTo: "",

    cSubject: "Vacancy Notice",

    cMsg: "Please see the vacancy notice form attached."

});

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

If you want to send an email that validates fields before sending then I would suggest using a button script. Put the word "Send" on the button. Then acquire all the required fields and test them.

 

You can read about document/form level validation here:

https://www.pdfscripting.com/public/Form-Data-Validation.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
Community Beginner ,
Dec 10, 2025 Dec 10, 2025

Hello try67!

I am working on an interatice English placement test and am a bit lost in how to script the validation of a series of dropdowns.... could you please give me some guidance....thanks!!!

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 ,
Dec 11, 2025 Dec 11, 2025

Sure, but I need to first understand what exactly you're trying to achieve... Can you describe your goal, and what you mean by "validating the drop-downs", exactly?

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 Beginner ,
Dec 11, 2025 Dec 11, 2025

Thank you for your quick reply!

I have a 100 dropdown question placement test, part a 50 questions & part b 50 questions. Each question has four possible responses; a, b, c, x, where x equals no response. I would like to find away, on email with a dedicated button, to evaluate the answers, correct or incorrect, x would be 0, each correct answer would equal 1 point. I would like to have the score for each part shown in a box at the end of the each part of the test, but only after the email button has been hit so I will be the only one to see these results.... what do you think?

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 Beginner ,
Dec 11, 2025 Dec 11, 2025

Screen shots......1.jpg2.jpg3.jpg4.jpg5.jpg

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 ,
Dec 11, 2025 Dec 11, 2025

It's possible, but will require a custom-made script. Also, be aware that the email can't be sent automatically back to you, so the user will always be able to open the file with the results and view them. It is possible to submit data back to a web-server without user interaction, but that is more complicated. Another option is to put the result in a hidden field, which you can then make visible on your end. All of this requires a custom-made solution, though.

If you're interested in hiring a professional to create it for you, feel free to contact me privately by clicking my user-name and then on the blue "Message" button.

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 Beginner ,
Dec 11, 2025 Dec 11, 2025

Thanks again! I ma afraid it is a very / no budget project 😞

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 ,
Dec 11, 2025 Dec 11, 2025

Well, if you want to do it yourself you can use something like this as the custom calculation script of a (hidden) text field that will hold the score for one question, say question 1 and that the right answer for it is "b":

event.value = (this.getField("1").valueAsString=="b") ? 1 : 0;

You can then also create a total score field that adds all the values of the individual fields to get the final score. You can use the built-in Sum option under the Calculate tab for that.

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 Beginner ,
Dec 11, 2025 Dec 11, 2025

Great! Thanks again!

I will work with this a bit later and let you know how it goes... 😉

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 Beginner ,
Dec 11, 2025 Dec 11, 2025

Hey again!
Ive tried what you sent but the vaues are not showing in the text filed with the sum cakculation....

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 Beginner ,
Dec 11, 2025 Dec 11, 2025

Hi,

The value of 1 does not show in the hidden box....

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 ,
Dec 11, 2025 Dec 11, 2025

Check the JS Console for error messages. If you still can't figure it out, share the file for further help.

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 Beginner ,
Dec 12, 2025 Dec 12, 2025
LATEST

I found the solution. Thanks!!

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