Skip to main content
Participant
September 20, 2017
Answered

Newbie need help with JavaScript

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

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
September 20, 2017

Yes, that is correct


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

6 replies

try67
Community Expert
Community Expert
September 20, 2017

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

Translate
Participant
September 20, 2017

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

Translate
try67
Community Expert
Community Expert
September 20, 2017

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

Translate