Newbie need help with JavaScript

Community Beginner ,
Sep 19, 2017

Copy link to clipboard

Copied

Hello everyone,

im new to using JavaScript and could really need some help. I´ve created a form in Adobe pro and what i want is the following:

If field "Comment1" contains any text user is enforced to pick a choice from drop down menu "R1" and "L1". Is it best to use validation script for this? Or calculation script?

I got over 100 rows that i want the same function in, they are named: Comment1, R1, L1; Comment2, R2, L2; Comment3, R3, L3; And so on..

I hope this post makes some sense,

Thanks in advance, Adrian

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

OK, then I misunderstood before. Enter this code as a doc-level script:

function setDropdownsAsRequired() {

    var fieldNumber = event.target.name.replace("Comment", "");

    this.getField("R"+fieldNumber).required = (event.value!="");

    this.getField("L"+fieldNumber).required = (event.value!="");

}

Then you just need to call it from the custom validation script of your Comment fields, like this:

setDropdownsAsRequired();

TOPICS
Acrobat SDK and JavaScript, Windows

Views

114

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

Newbie need help with JavaScript

Community Beginner ,
Sep 19, 2017

Copy link to clipboard

Copied

Hello everyone,

im new to using JavaScript and could really need some help. I´ve created a form in Adobe pro and what i want is the following:

If field "Comment1" contains any text user is enforced to pick a choice from drop down menu "R1" and "L1". Is it best to use validation script for this? Or calculation script?

I got over 100 rows that i want the same function in, they are named: Comment1, R1, L1; Comment2, R2, L2; Comment3, R3, L3; And so on..

I hope this post makes some sense,

Thanks in advance, Adrian

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

OK, then I misunderstood before. Enter this code as a doc-level script:

function setDropdownsAsRequired() {

    var fieldNumber = event.target.name.replace("Comment", "");

    this.getField("R"+fieldNumber).required = (event.value!="");

    this.getField("L"+fieldNumber).required = (event.value!="");

}

Then you just need to call it from the custom validation script of your Comment fields, like this:

setDropdownsAsRequired();

TOPICS
Acrobat SDK and JavaScript, Windows

Views

115

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
Sep 19, 2017 0
Most Valuable Participant ,
Sep 20, 2017

Copy link to clipboard

Copied

"Enforce" how, exactly? You can set them as required, but only gets validated when the form is submitted (unless a script is used to validate it during other events). Is that what you mean?

Also, what are the actual field names of the drop-downs? Not just their options...

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...
Sep 20, 2017 1
Community Beginner ,
Sep 20, 2017

Copy link to clipboard

Copied

Thanks for your reply!

Yes, setting them as required is exactly what i mean. The field names of the dropdowns are as i wrote: R1, L1 for the first row and then R2, L2 for second row and so on. 

Thanks in advance, Adrian

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...
Sep 20, 2017 0
Most Valuable Participant ,
Sep 20, 2017

Copy link to clipboard

Copied

So there are two drop-downs for each comment field?

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...
Sep 20, 2017 1
Community Beginner ,
Sep 20, 2017

Copy link to clipboard

Copied

Yes, that is correct

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...
Sep 20, 2017 0
Most Valuable Participant ,
Sep 20, 2017

Copy link to clipboard

Copied

OK, then I misunderstood before. Enter this code as a doc-level script:

function setDropdownsAsRequired() {

    var fieldNumber = event.target.name.replace("Comment", "");

    this.getField("R"+fieldNumber).required = (event.value!="");

    this.getField("L"+fieldNumber).required = (event.value!="");

}

Then you just need to call it from the custom validation script of your Comment fields, like this:

setDropdownsAsRequired();

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...
Sep 20, 2017 1
Community Beginner ,
Sep 20, 2017

Copy link to clipboard

Copied

It worked and was exactly what i was after!

Thanks alot, you saved my day!

Regards, Adrian

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...
Sep 20, 2017 0