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

Populating textboxes based on content in dropdown boxes

Community Beginner ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

I'm pretty new to JavaScript so I have very little idea how to achieve this. But I'm learning. 🙂

I have three (3) dropdown boxes on a PDF form where the user can select a series of courses. All dropdown boxes contain the same list of courses, for example...

Course A - Design widgets

Course B - Assemble widgets

Course C - Test widgets

Course D - Paint widgets

Course E - Pack widgets

When a selection is made in one of the dropdowns (Course1) an adjacent textbox (NominalHours_Course1) needs to display the number of hours that the course typically runs for (e.g. 5, 8, 12, 15, etc.). This is a predetermined value for each course and needs to be retrieved from a table... (I assume stored somewhere in the document?).

I'm after the same sort of functionality as the MS Excel VLOOKUP function.

Reading some of the posts on this forum, it looks like the relationship between course and hours should be in a document level script, allowing the "Nominal Hours" values to be referenced by any of the dropdown boxes and textboxes. This would also make it easier to change values if required since the changes would only need to be made in the one location.

I have no idea where to start with this. I have tried working through the JavaScript Tutorials on w3schools.com but I think I might be trying to bite off more then I can chew (being such a beginner at JavaScript).

Hoping someone can help.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

4.1K

Translate

Translate

Report

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 , Apr 20, 2017 Apr 20, 2017

Sure. OK, so you can place this code as your doc-level script:

var courseData = {

"Course A - Design widgets" : 5,

"Course B - Assemble widgets" : 8,

"Course C - Test widgets" : 12,

"Course D - Paint widgets" : 15,

"Course E - Pack widgets" : 21

};

function calcCourseHours(dropdownFieldName) {

    var v = courseData[this.getField(dropdownFieldName).value];

    if (v) event.value = v;

    else event.value = "";

}

And then as the custom calculation of your text field enter this code:

calcCourseHours("Course1");

...

Votes

Translate

Translate
Community Expert ,
Jul 10, 2018 Jul 10, 2018

Copy link to clipboard

Copied

It looks like something I've written, actually...

Anyway, you could also run this code from the JS Console to update the

fields.

Votes

Translate

Translate

Report

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 Beginner ,
Jul 10, 2018 Jul 10, 2018

Copy link to clipboard

Copied

Yes it was yours. Thanks.

You suggested it earlier in this thread, over was 12 months ago.

Votes

Translate

Translate

Report

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 ,
Jul 10, 2018 Jul 10, 2018

Copy link to clipboard

Copied

Unless the data is changed frequently it's not necessary, to be honest.

Votes

Translate

Translate

Report

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 Beginner ,
Jul 10, 2018 Jul 10, 2018

Copy link to clipboard

Copied

Think I'm gonna leave things alone now that the form is working perfectly again.

Cheers, Steve

Votes

Translate

Translate

Report

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 Beginner ,
Apr 25, 2019 Apr 25, 2019

Copy link to clipboard

Copied

I have a similar request to this. I am interested in trying to make annotations to pictures on a PDF, I want them to reference a text document. I've been poking around trying to find something similar, but haven't been able to find much. I'm checking out this link to see if it was I'm looking for.

Votes

Translate

Translate

Report

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 ,
Apr 25, 2019 Apr 25, 2019

Copy link to clipboard

Copied

LATEST

Please post your question to a new thread, with a clear explanation of what you want to do.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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