Skip to main content
Participant
July 12, 2017
Question

if statement help!

  • July 12, 2017
  • 1 reply
  • 267 views

Hello everyone, 

I dont know anythgin about javascript so that is why i am here, I am creating a form where I have 2 columns, one with a dropdown options and the 2nd one with a date, so if the dropdown do not = blank then I want to populate the current date, how can this be done?

This topic has been closed for replies.

1 reply

Karl Heinz  Kremer
Community Expert
Community Expert
July 12, 2017

Let me start with this: Do yourself a favor and learn how JavaScript works. You cannot copy and paste your way to a successful solution if you don't know what you are doing. You need to be able to adapt what you find here to your specific requirements, and fix potential problems when the requirements change in the future. Here is some information about how to learn to program in JavaScript for Acrobat: Learning to Program JavaScript for Adobe Acrobat - KHKonsulting LLC

What you want to do is test one field for content, and then set a second field to some information. This is normally done with a custom calculation script in the second field. Let's say you have a field named "Dropdown", to get it's value and test if it's not empty, you would use something like this:

if (this.getField("Dropdown").value != "") {

  event.value = "some information";

}

To get the current date in the format "dd/mm/yyyy" into the field, you can change line #2 to this:

event.value = util.printd("mm/dd/yyyy", new Date());

Depending on how you set up your dropdown list, this may still not work: Via the user interface, you cannot create a truly blank entry. You would have to use e.g. one space. If that is what you did, you need to adjust line #1 in the code above to test for "unequal to one space":

if (this.getField("Dropdown").value != " ") {

Participant
July 24, 2017

Thank you Karl, I know it will be beneficial for me to learn it, but I dont use it js at all just this time, the script works but I am missing one part of it and I have been trying to figure it out myself but no luck, I want to show the DATE if there is a value in the dropdown beside the "space" and if the value is "space" (blank) then just show me blank