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

Help with script in form

Community Beginner ,
Aug 02, 2020 Aug 02, 2020

Trying to have an alert pop up only if two conditions are met. The script is running On blur for the text box. First condition is the text box and second is a check box just before it. Right now the message is popping up everytime we tab to the text field regardly if the conditions are met.

 

if ((this.getField("EthnicityOther").value.length == 0) && (this.getField("Other1").value = "on"));
{
app.alert("When Other is selected, please enter a description.")
f.setFocus()
}

TOPICS
Acrobat SDK and JavaScript
635
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 ,
Aug 02, 2020 Aug 02, 2020

Compare the operators you use in the first and second parts of your if-condition... See any differences?

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 ,
Aug 02, 2020 Aug 02, 2020

Also, where did you define the "f" variable?

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 ,
Aug 02, 2020 Aug 02, 2020

sorry, I originally defined it...I've made so many changes trying to get it to work that I had removed it. Pretty new to this so been researching code to use.

 

I just tried this and I still get the pop up even if the Other1 field is not checked. Thanks for the help!

 

f = this.getField("EthnicityOther")

if ((this.getField("EthnicityOther").value.length == 0) && (this.getField("Other1").value == "on"));
{
app.alert("When Other is selected, please enter a description.")
f.setFocus()
}

 

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 ,
Aug 02, 2020 Aug 02, 2020

- Remove the semi-colon after the if-statement.

- Make sure the export value of the "Other1" field is indeed "on" and not something else (by default it's "Yes").

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 ,
Aug 02, 2020 Aug 02, 2020

Well I just wish I had posted this 3 days ago. It's working!! Thanks so much for taking the time to respond.

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 ,
Aug 02, 2020 Aug 02, 2020
LATEST

I did need to change the "on" to "yes".

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