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

Javascript to hide/show text field

Community Beginner ,
Jan 11, 2021 Jan 11, 2021

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
14.6K
Translate
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
1 ACCEPTED SOLUTION
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"...

View solution in original post

Translate
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

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;

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

 

Translate
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

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

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

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

Translate
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 ,
Jan 02, 2025 Jan 02, 2025

Greetings! I am not sure if you still see this thread but I have a question that relates to the OP's original question, although they sort of strayed from it later on...


I am trying to show/hide a text box based on the date selected in a dropdown.

Date field = "Renewal Date"

Text Box = "Expired"

The Expired text box is simply a text field with the word "EXPIRED!" typed into it. I have it set as Read Only, no fill and no border. 

 

So, for example -

if the Renewal date selected is BEFORE today's date, the Expired text box will be displayed.

if the Renewal date is AFTER today's date, the Expired text box will stay hidden.

 

I tried multiple variations of similar answers but none work exactly. Sometimes it will show the text field, no matter the date selected. Or it will hide the field. But I am not able to show/hide as the date is changed.

 

Here's a script I pieced together using your responses here and elsewhere. If you can provide some insight I would appreciate it!

 

Currently this is in the Validation section of the Date Field.

 

// Date selected in Renewal ATD
var ATD = new Date(event.value);

// Today's Date
var today = new Date();

// EXPIRED!
var expiredATD = this.getField("EXPIRED!");

if(ATD < today) {
expiredATD.display = display.visible;
} else {
expiredATD.display = display.hidden;
}

if(event.value == ""){
expiredATD.display = display.hidden;
}

 

So, to recap:

- display EXPIRED field if Date selected is BEFORE today's date.

- hide EXPIRED field if Date selected is AFTER today's date.

- hide EXPIRED field if form is blank and no date is selected.

 

Thanks again!

Translate
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 02, 2025 Jan 02, 2025

What if it's today's date?

Is your field named "Expired" or "EXPIRED!"?

Translate
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 ,
Jan 02, 2025 Jan 02, 2025

Oops! Forgot to add the today's date part.

 

So it would be a RENEWAL date of TODAY or EARLIER. And that would cause the EXPIRED! text field display to be visible.

 

The text field name in my document is EXPIRED!. I just wrote EXPIRED in my question. 

Translate
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 02, 2025 Jan 02, 2025

Try this:

var enteredDate = event.value;
var expiredField = this.getField("EXPIRED!");

if (enteredDate) {
 var inputDate = util.scand("mm/dd/yyyy", enteredDate);
 inputDate.setHours(0, 0, 0, 0);

 var today = new Date();
  today.setHours(0, 0, 0, 0);

 expiredField.display = (inputDate <= today) ? display.visible : display.hidden;} 
else {
 expiredField.display = display.hidden;}
Translate
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 ,
Jan 02, 2025 Jan 02, 2025
LATEST

Oh my gosh! You are a genius! Thank you so much, it finally works! 

I actually asked ChatGPT before posting here and none of the answers I got on there actually worked for what I was trying to do. 

So, thank you again for your help!

 

P.S. I don't suppose Adobe supports a way to make the EXPIRED! text blink in/out of view MrCreepus_0-1735851829667.pngexpand image

 

Translate
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

Try this:

 

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

{

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

}

else

{

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

}


PDF Acrobatic, InDesigner & Photoshoptographer
Translate
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 ,
Jan 12, 2021 Jan 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.

Translate
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

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;}

Translate
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

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.

Translate
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

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;

Translate
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

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

Translate
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

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

Translate
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

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;

Translate
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

thanks

Translate
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