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

Name and Pin if true auto populate another field with a number

New Here ,
May 22, 2025 May 22, 2025

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.

TOPICS
PDF
448
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 ,
May 22, 2025 May 22, 2025

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.

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 ,
May 22, 2025 May 22, 2025

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

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 ,
May 22, 2025 May 22, 2025

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;
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 ,
May 22, 2025 May 22, 2025

Thank you I will try that.

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 ,
May 23, 2025 May 23, 2025

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 = "";

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 ,
May 23, 2025 May 23, 2025

You're missing two curly brackets at the end of the code.

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 ,
May 23, 2025 May 23, 2025

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.

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 ,
May 23, 2025 May 23, 2025

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

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 ,
May 23, 2025 May 23, 2025

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

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 ,
May 23, 2025 May 23, 2025

Check console for errors.

Make sure field names and values are correct.

If possible, share your file with us.

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 ,
May 23, 2025 May 23, 2025

I have attached the file below. I checked field names and values. Than k you for the help.

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 ,
May 23, 2025 May 23, 2025

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.

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 ,
May 23, 2025 May 23, 2025

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

 

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 ,
May 23, 2025 May 23, 2025

I will try that. 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
New Here ,
May 23, 2025 May 23, 2025
LATEST

yeah it worked.

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