Highlighted

Help with script in form

New Here ,
Aug 02, 2020

Copy link to clipboard

Copied

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, PDF forms

Views

65

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Help with script in form

New Here ,
Aug 02, 2020

Copy link to clipboard

Copied

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, PDF forms

Views

66

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 02, 2020 0
Most Valuable Participant ,
Aug 02, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 02, 2020 0
Most Valuable Participant ,
Aug 02, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 02, 2020 0
New Here ,
Aug 02, 2020

Copy link to clipboard

Copied

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()
}

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 02, 2020 0
Most Valuable Participant ,
Aug 02, 2020

Copy link to clipboard

Copied

- 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").

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 02, 2020 0
New Here ,
Aug 02, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 02, 2020 0
haley365 LATEST
New Here ,
Aug 02, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 02, 2020 0