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

Hiding and showing text fields based on value of one text field

New Here ,
Aug 23, 2018 Aug 23, 2018

Copy link to clipboard

Copied

Can someone help me on how to made text fields visible/hidden based on the value of another text field?

I have 3 text fields; Field1, Field2 and Field3.

I want to set up my form so that if the value of Field1 is less than 10, Field2 will be hidden and Field3 will be visible for people to enter a value in that field. If Field1 is 10 or more, Field3 should be hidden and Field2 should be visible and on focus.

It seems like I need a custom validation code for Field1 but I have no clue how to code.

TOPICS
Create PDFs

Views

1.3K

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 , Aug 24, 2018 Aug 24, 2018

Use this code as the custom validation script of Field1:

var f2 = this.getField("Field2");

var f3 = this.getField("Field3");

if (event.value=="") {

    f2.display = display.hidden;

    f3.display = display.hidden;

    f2.value = "";

    f3.value = "";

} else if (Number(event.value)<10) {

    f2.display = display.hidden;

    f3.display = display.visible;

    f2.value = "";

} else {

    f2.display = display.visible;

    f3.display = display.hidden;

    f3.value = "";

}

Votes

Translate

Translate
Community Expert ,
Aug 23, 2018 Aug 23, 2018

Copy link to clipboard

Copied

What about if Field1 is empty? Should then both the fields be hidden?

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
New Here ,
Aug 23, 2018 Aug 23, 2018

Copy link to clipboard

Copied

Actually I want to make Field1 a "required" field so that it will never be empty.

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
LEGEND ,
Aug 23, 2018 Aug 23, 2018

Copy link to clipboard

Copied

It will be empty until filled in unless you are providing a default value.

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 ,
Aug 24, 2018 Aug 24, 2018

Copy link to clipboard

Copied

The two things are not related to each other. A required field can be empty.

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
New Here ,
Aug 24, 2018 Aug 24, 2018

Copy link to clipboard

Copied

Oh I see. If that's the case, I'd like for both to be hidden if Field1 is empty

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 ,
Aug 24, 2018 Aug 24, 2018

Copy link to clipboard

Copied

Use this code as the custom validation script of Field1:

var f2 = this.getField("Field2");

var f3 = this.getField("Field3");

if (event.value=="") {

    f2.display = display.hidden;

    f3.display = display.hidden;

    f2.value = "";

    f3.value = "";

} else if (Number(event.value)<10) {

    f2.display = display.hidden;

    f3.display = display.visible;

    f2.value = "";

} else {

    f2.display = display.visible;

    f3.display = display.hidden;

    f3.value = "";

}

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
New Here ,
Aug 24, 2018 Aug 24, 2018

Copy link to clipboard

Copied

This worked perfectly. Thank you!!!!

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
Participant ,
Jun 12, 2019 Jun 12, 2019

Copy link to clipboard

Copied

I have similar case.

I have two fields. First is a text field and other dropdown.

I want to display/show dropdown only when I enter text in field 1.Screenshot (54).png

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 12, 2019 Jun 12, 2019

Copy link to clipboard

Copied

You can use I provided above to do that.

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
Participant ,
Jun 12, 2019 Jun 12, 2019

Copy link to clipboard

Copied

I do not have the number value. It is the name field. When a person writes 3 characters second field should be displayed.

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 12, 2019 Jun 12, 2019

Copy link to clipboard

Copied

LATEST

So it is 3 characters, or any value at all?

The basic code is the same:

var f2 = this.getField("Field2"); 

if (event.value=="") { 

    f2.display = display.hidden; 

} else { 

    f2.display = display.visible; 

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