Skip to main content
Inspiring
February 7, 2018
Answered

Is a drop-down window considered a string?

  • February 7, 2018
  • 2 replies
  • 591 views

I ask this because I have and if/then statement set up where if a field has a keyword inputted, then when a submit button is pushed it will send an email to one of two groups.  I'm changing it because users are not "reading" the instructions and half the time, are not putting in the keyword when they should be so it's being emailed to the wrong group.

So I want to change the "if/then" to a different field but that field is a drop-down menu and it doesn't work with the ".valueAsString.indexOf("Keyword") == 0.

Here's part of what I'm working with:

var keyWord = (this.getField("Org").valueAsString.indexOf("Company Name") == 0);

if (this.getField("Signature").value != "" && keyWord == true) {

    this.mailDoc({bUI:true, cTo:sendTo, cCc:copyTo...

I have to run this script in the Button Field.

This topic has been closed for replies.
Correct answer SIPRNet11

The "Keyword" should've been "Company Name"...sorry.

2 replies

Thom Parker
Community Expert
Community Expert
February 7, 2018

the value of a dropdown is a string in the same sense that all field values are strings. If you use the "field.valueAsString" property it's guaranteed.

If the code is not working, it has nothing to do with whether or not the dropdown value is a string. The most likely issue are the values returned by the drop down.  I'm assuming that the dropdown is named "Org"?

To find out the value returned from the dropdown, run this code from the console window:

this.getField("Org").value

You'll find a tutorial on the Console Window here:Free Video Content & Full Listing of Available Videos

I'd also suggest rewriting the if statement to make the conditions more explicit

Like this:

if ((this.getField("Signature").value != "") && keyWord) {

is it not necessary to test a boolean for "true", since its already true or false.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
SIPRNet11Author
Inspiring
February 7, 2018

That worked Thom!  Thank you sir!

SIPRNet11AuthorCorrect answer
Inspiring
February 7, 2018

The "Keyword" should've been "Company Name"...sorry.