Skip to main content
Participant
January 12, 2021
해결됨

Javascript to hide/show text field

  • January 12, 2021
  • 2 답변들
  • 16909 조회

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

 

최고의 답변: try67

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

2 답변

JR Boulay
Community Expert
Community Expert
January 12, 2021

Try this:

 

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

{

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

}

else

{

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

}

Acrobate du PDF, InDesigner et Photoshopographe
Trent154A작성자
Participant
January 12, 2021

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

try67
Community Expert
Community Expert
January 12, 2021

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;

Trent154A작성자
Participant
January 12, 2021

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

 

try67
Community Expert
try67Community Expert답변
Community Expert
January 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"...