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.
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");
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.
Copy link to clipboard
Copied
Yes it was yours. Thanks.
You suggested it earlier in this thread, over was 12 months ago.
Copy link to clipboard
Copied
Unless the data is changed frequently it's not necessary, to be honest.
Copy link to clipboard
Copied
Think I'm gonna leave things alone now that the form is working perfectly again.
Cheers, Steve
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.
Copy link to clipboard
Copied
Please post your question to a new thread, with a clear explanation of what you want to do.