Copy link to clipboard
Copied
I am a novice to javascript and I am using Adobe Pro. I am trying to get a name and pin combination and if true have a different field auito populate a prior approval number of 8 digits. I have tried numerous suggetions from the community but I have not had success. I basically have no code to create this. Thank you for your help.
Copy link to clipboard
Copied
You need to provide some more info. By "pin" do you mean password, as in a login? If so, where is the login information stored? In your code? Are you aware that that code can be viewed by anyone who has Acrobat (or other similar tools), and is therefore not secured at all?
Also, what "approval number" do you want to display? A fixed one? A random one? Something else?
Please be more specific.
Copy link to clipboard
Copied
Great questions. I am not to worried about overall security. Then pin is a four digit pin. I can store in a excel file or in code, would need to know ho to do excel file. The approval number is a fixed assigned number to each person and needs to be in a text field in the form. Thank you
Copy link to clipboard
Copied
You can use something like this as the Mouse Up event of a button field, then:
var name = this.getField("Name").valueAsString;
var pin = this.getField("Pin").valueAsString;
var approvalNumber = "";
if (name=="John Doe" && pin=="1234") approvalNumber = "98765432";
else if (name=="Jane Smith" && pin=="5555") approvalNumber = "12234569";
// etc.
this.getField("ApprovalNumber").value = approvalNumber;
Copy link to clipboard
Copied
Thank you I will try that.
Copy link to clipboard
Copied
Here is my code. i am getting the error, exception in line 14 of function top_level, script Field:Calculate. Can you help me figure this out. Thank you.
function autoFill() {
var name = this.getField("Name").value;
var pin = this.getField("Pin").value;
if (name === "Yookyung Kim" && pin === "1492") {
this.getField("Approval Number").value = "12481570";
} else if (name === "Madison St.John" && pin === "8107") {
this.getField("Approval Number").value = "12453397";
} else {
app.alert("Invalid Name and PIN combination.");
this.getField("Approval Number").value = "";
Copy link to clipboard
Copied
You're missing two curly brackets at the end of the code.
Copy link to clipboard
Copied
Thank you. I put the curly brackets in. Should this script be in the Approval Number Calculate tab or Validate tab? It doesn't auto populate the Approval number Field.
Copy link to clipboard
Copied
It needs to be in a button. If you want it to execute automatically then move it to the Calculation event of "Approval Number", remove the alert and change all instances of:
this.getField("Approval Number").value = ...
To:
event.value = ...
Copy link to clipboard
Copied
Here is the correted code. I put the Pin number and then the name and hit enter and Approval Number does not populate. Any help is great. Thank you.
function autoFill() {
var name = this.getField("Name").value;
var pin = this.getField("Pin").value;
if (name === "Yookyung Kim" && pin === "1492") {
event.value = "12481570";
} else if (name === "Madison St.John" && pin === "8107") {
event.value = "12453397";
} else {
event.value = "";
}
}
Copy link to clipboard
Copied
Check console for errors.
Make sure field names and values are correct.
If possible, share your file with us.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Here is what I am looking to do. When the person opens the PDF they reset form and then put in thier name and pin. When that happens thier approval number will auto populate indicating the proper name and pin combination are correct. If it is not correct, nothing will happen. Thank you for your help.
Copy link to clipboard
Copied
Remove function and use two equal signs when checking for pin, like this:
var name = this.getField("Name").value;
var pin = this.getField("Pin").value;
if (name === "Yookyung Kim" && pin == "1492") {
event.value = "12481570";}
else if (name === "Madison St.John" && pin == "8107") {
event.value = "12453397";}
else {
event.value = "";}
Copy link to clipboard
Copied
I will try that. Thank you very much.
Copy link to clipboard
Copied
yeah it worked.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now