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

Get value of text field?

New Here ,
Aug 25, 2017 Aug 25, 2017

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);

TOPICS
Acrobat SDK and JavaScript , Windows
9.6K
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

correct answers 1 Correct answer

Community Expert , Aug 25, 2017 Aug 25, 2017

Change:

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

To:

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

Translate
Community Expert ,
Aug 25, 2017 Aug 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.

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 ,
Aug 25, 2017 Aug 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);

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 ,
Aug 25, 2017 Aug 25, 2017

Change:

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

To:

var bAmount = Number(this.getField("buildingsNumber").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 ,
Aug 25, 2017 Aug 25, 2017

ons step closer! This worked however now the pages only get inserted after the second time I click the checkbox.

So when the form is empty, i insert the number of pages into the buildingsNumber field and then i check the checkbox which should then spawn the pages... but it doesn't spawn the pages until I click the already checked checkbox again?

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 ,
Aug 25, 2017 Aug 25, 2017
LATEST

Not sure I quite follow you, but you can try using the Mouse Up action of the check-box, not Mouse Down.

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