Skip to main content
warm_Lullaby5CA0
Known Participant
August 25, 2017
Answered

Get value of text field?

  • August 25, 2017
  • 1 reply
  • 10053 views

Hoping someone can help me...

I have a adobe form with a text input field alongside a checkbox. I want my javascript to basically do the following: check the number inserted by the user into the text field and then spawn template pages (amount equal to that of the number inserted in the text field).

This is the code I have so far however it is not working, can someone tell me what I am doing wrong? (by the way, the code is inserted as a mouse down action on the checkbox). The name of the text field is "buildingsNumber" and the template name is "buildings".

var bAmount = document.getElementById("buildingsNumber").value;

var t = this.getTemplate("buildings");

for (var i = 1; i <= bAmount; i++)

t.spawn(i, true, false, XO);

This topic has been closed for replies.
Correct answer try67

Change:

var bAmount = this.getField("buildingsNumber");

To:

var bAmount = Number(this.getField("buildingsNumber").value);

1 reply

try67
Community Expert
Community Expert
August 25, 2017

You're using JS code that was written for a web-page. It will not work in a PDF.

Replace this part:

document.getElementById

With:

this.getField

Also, you've seemed to have copied the spawn command, but not in full. You're missing the first call to spawn, which is then saved in the XO variable. Your code as it stand will not work.

warm_Lullaby5CA0
Known Participant
August 25, 2017

I have fixed the code to the below... but it is not inserting the pages that I want it to. Is this because of the spawn command not being used properly? I'm not 100% sure how to use the spawn command properly. It is not returning any errors when I run the code though. and if I change the for statement to the following: for (var i = 1; i <= 3; i++) , then it works and inserts 3 pages of the template that I want it to insert.

var bAmount = this.getField("buildingsNumber");

var t = this.getTemplate("buildings");

for (var i = 1; i <= bAmount; i++)

t.spawn(i, true, false);

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 25, 2017

Change:

var bAmount = this.getField("buildingsNumber");

To:

var bAmount = Number(this.getField("buildingsNumber").value);