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
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"...
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;
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
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"...
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
What if it's today's date?
Is your field named "Expired" or "EXPIRED!"?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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;}
Copy link to clipboard
Copied
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
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;
}
PDF Acrobatic, InDesigner & Photoshoptographer
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.
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;}
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.
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;
Copy link to clipboard
Copied
Remove two curly brackets. You should change v10 to 10.
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
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;
Copy link to clipboard
Copied
thanks

