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

Javascript to hide/show text field

New Here ,
Jan 11, 2021 Jan 11, 2021

Copy link to clipboard

Copied

I am completely new to doing javascript, and I am trying to complete a form to show or hide a particular text field.  I know there are posts on performing the hide/show condition with a checkbox using javascript; and if all else fails I will use this. 

 

However, I am wondering if it is possible for hiding or showing a text field using a date picker field?  For example, If the date field is blank, I want the text field to show, and if a date is selected the text field goes away.  Then, if the date field is cleared out, the text field reappears. Make sense?

 

Thank you,

 

TJ

 

TOPICS
How to , JavaScript , PDF forms

Views

9.2K

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 , Jan 12, 2021 Jan 12, 2021

No, it will not hide the date field. it will hide the other field, if you enter its name in the part in quotes where I put "Name of other field"...

Votes

Translate

Translate
Community Expert ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

Sure, that's possible.

As the custom Validation script of the date field enter the following:

 

this.getField("Name of other field").display = (event.value=="") ? display.visible: display.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 ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

Thank you Try67.  This will hide my date field, however, I am looking for hiding a different text field when a date is selected.

 

So, I though if I did the following as an if statement, might do what I am looking for.

 

if(the.getField("Date6_af_date").display=(event.value==""));

{

this.getField("Text1").display = display.hidden;

}

else

{

this.getField("Text1").display = display.visible;

}

 

But I get a Syntax Error.  So I am missing something

 

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 ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

No, it will not hide the date field. it will hide the other field, if you enter its name in the part in quotes where I put "Name of other field"...

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 ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

I am sorry, I realized I put the wrong field name in the parentheses.  It works great.  Thank you very much.

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 ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

Try this:

 

if (this.getField("Date6_af_date").value == "");

{

this.getField("Text1").display = display.hidden;

}

else

{

this.getField("Text1").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
New Here ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

Thank you JR for your recommendation.  Try67's worked correctly once I realized I made a mistake when I entered the field name.

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 ,
Sep 03, 2022 Sep 03, 2022

Copy link to clipboard

Copied

I am trying your code but I want my field CoverCF not visible when PlatesOrdered is less than ten.

I tried the below, but get a syntex error:

if (this.getField("PlatesOrdered").value < "10");
{
this.getField("CoverCF").display = display.visible;
}
else
{
this.getField("CoverCF").display = display.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
Community Expert ,
Sep 03, 2022 Sep 03, 2022

Copy link to clipboard

Copied

In the first line, remove the semicolon.

Not sure what you want to happen but the way you write script, it will display "CoverCF" field even when "PlatesOrdered" field is empty or 0 too.

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 ,
Sep 03, 2022 Sep 03, 2022

Copy link to clipboard

Copied

I now have this script, but getting a syntax error. I am trying to have text boxes cover the fields behind it so they cannot be seen till the orders get to 10

 

if(this.getField("PlatesOrdered").value < v10 )

this.getField("CoverCF").display = display.visible;

} else { this.getField("CoverCF").display = display.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
Community Expert ,
Sep 04, 2022 Sep 04, 2022

Copy link to clipboard

Copied

Remove two curly brackets. You should change v10 to 10.

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 ,
Sep 04, 2022 Sep 04, 2022

Copy link to clipboard

Copied

Here is what I am putting in the validation, but the text box remains visible.

 

if (this.getField("PlatesOrdered").value < 10)

this.getField("CoverCF").display = display.display;

else this.getfield("CoverCF").display = display.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
Community Expert ,
Sep 04, 2022 Sep 04, 2022

Copy link to clipboard

Copied

Change display.display to display.visible and in last line change this.getfield to this.getField.

If you use script as validation in "PlatesOrdered" field you can also simplify it like this:

this.getField("CoverCF").display = Number(event.value) < 10 ? display.visible : display.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 ,
Sep 04, 2022 Sep 04, 2022

Copy link to clipboard

Copied

LATEST

thanks

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