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

Making several fields required if value in prior field

Community Beginner ,
Jun 05, 2019 Jun 05, 2019

Copy link to clipboard

Copied

Hey there.

I have a form for naming corporate officers. One company can have 2, another can have 22 so what I would like to do is:

If information is entered into "First Name" then require

"Last Name"

"Title"

"DOB"

Any help is GREATLY appreciated!!!

TOPICS
Acrobat SDK and JavaScript

Views

291

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
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 05, 2019 Jun 05, 2019

You are sooo close.  Try this.

var sVal = getField("ar_first_name_2").valueAsString;

if (sval != "") {

getField("ar_last_name_2").required = true;

getField("ar_title_position_2").required = true;

getField("ar_dob_2").required = true;

getField("ar_address_2").required = true;

getField("ar_city_2").required = true;

getField("ar_state_2").required = true;

getField("ar_postalcode_2").required = true;

}

Actually, you should use this code, so that required is turned off if the user deletes the first name.

This co

...

Votes

Translate

Translate
Community Beginner ,
Jun 05, 2019 Jun 05, 2019

Copy link to clipboard

Copied

Sorry I should have posted what I tried and failed:

var sVal = getField("ar_first_name_2").valueAsString;

if (inputtx.value.length != 0) {

getField("ar_last_name_2").required = true;

getField("ar_title_position_2").required = true;

getField("ar_dob_2").required = true;

getField("ar_address_2").required = true;

getField("ar_city_2").required = true;

getField("ar_state_2").required = true;

getField("ar_postalcode_2").required = true;

}

and also tried this one to no avail.  

var sVal = getField("ar_first_name_2").valueAsString;

if (!sval) {

getField("ar_last_name_2").required = true;

getField("ar_title_position_2").required = true;

getField("ar_dob_2").required = true;

getField("ar_address_2").required = true;

getField("ar_city_2").required = true;

getField("ar_state_2").required = true;

getField("ar_postalcode_2").required = true;

}

Votes

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
community guidelines
Community Expert ,
Jun 05, 2019 Jun 05, 2019

Copy link to clipboard

Copied

You are sooo close.  Try this.

var sVal = getField("ar_first_name_2").valueAsString;

if (sval != "") {

getField("ar_last_name_2").required = true;

getField("ar_title_position_2").required = true;

getField("ar_dob_2").required = true;

getField("ar_address_2").required = true;

getField("ar_city_2").required = true;

getField("ar_state_2").required = true;

getField("ar_postalcode_2").required = true;

}

Actually, you should use this code, so that required is turned off if the user deletes the first name.

This code is placed in a custom, format or validation script.

var bReq = (event.value != "");

getField("ar_last_name_2").required = bReq;

getField("ar_title_position_2").required = bReq;

getField("ar_dob_2").required = bReq;

    ...etc...

And since all the lines required the same code. I'd generalize the code into a document level function. This reduces human error when copying the code to all the different lines and makes it much easier to change the code.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Community Beginner ,
Jun 05, 2019 Jun 05, 2019

Copy link to clipboard

Copied

LATEST

Thom,

Thank you SOOO much, especially with the extra part of if they go in, type something, and then delete it!  You ROCK

Votes

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
community guidelines