Javascript Auto Populate
Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange
-
- User
- Posts: 4
- Joined: Wed Dec 13, 2023 1:50 pm
Javascript Auto Populate
Hey guys I have a fillable PDF form that I want to add a dropdown to, then once the dropdown selection is made it will autopopulate another text field. Trying to use the code below but its not working. I know I can set the export values of the dropdown/combobox and then just have whatever field inset the dropdowns value but I have a dropdown which then needs to populate 3 other fields with different values based on that dropdown fields value, so I need to build some sort of conditional if statement in the fields.
var rating = this.getField("Dropdown3").value;
if( rating = "1" ) event.value = "Test1";
else if( rating = "2" ) event.value = "Test2";
else event.value = "";
Any help would be greatly appreciated.
var rating = this.getField("Dropdown3").value;
if( rating = "1" ) event.value = "Test1";
else if( rating = "2" ) event.value = "Test2";
else event.value = "";
Any help would be greatly appreciated.
-
- Site Admin
- Posts: 19919
- Joined: Mon Jan 12, 2009 8:07 am
Re: Javascript Auto Populate
Hello ufc205,
Welcome to our forums. Please take a look at the attached sample file where you can see how a check box and drop down fields can control others.
The JS for the drop down is in a Custom Action script: Kind regards,
Stefan
Welcome to our forums. Please take a look at the attached sample file where you can see how a check box and drop down fields can control others.
The JS for the drop down is in a Custom Action script: Kind regards,
Stefan
You do not have the required permissions to view the files attached to this post.
-
- User
- Posts: 4
- Joined: Wed Dec 13, 2023 1:50 pm
Re: Javascript Auto Populate
Thank you very much for the fast reply and that is exactly what I needed! Works great now!
I have another challenge where I have a dropdown and based on the selection I'd like another specific dropdown to appear.
For example:
If Dropdown1 option 1 is selected will make Dropdown2 appear
If Dropdown1 option 2 is selected will make Dropdown3 appear
And then I'd need it to hide all the others and only show the correct one based off the Dropdown1 selection.
I have another challenge where I have a dropdown and based on the selection I'd like another specific dropdown to appear.
For example:
If Dropdown1 option 1 is selected will make Dropdown2 appear
If Dropdown1 option 2 is selected will make Dropdown3 appear
And then I'd need it to hide all the others and only show the correct one based off the Dropdown1 selection.
-
- Site Admin
- Posts: 19919
- Joined: Mon Jan 12, 2009 8:07 am
Re: Javascript Auto Populate
Hello ufc205,
Please take a look at the code for the checkboxes in the same file from the above post - they are turning the other fields on and off - so you can use the same however activate it on the Drop down selection being made!
Kind regards,
Stefan
Please take a look at the code for the checkboxes in the same file from the above post - they are turning the other fields on and off - so you can use the same however activate it on the Drop down selection being made!
Kind regards,
Stefan
-
- User
- Posts: 4
- Joined: Wed Dec 13, 2023 1:50 pm
Re: Javascript Auto Populate
Once again thank you kindly for that!! One thing I will note is that for dropdowns the JS has to be put in the Format Custom Calculation.
Is it possible once I have a page with a bunch of custom fields and JS to copy that page again with unique field names?
For example if original page has a field named "Dropdown1" the copy would create "Dropdown1_1" or something along those lines?
The reason being is I have about 50 drop downs on this one page that are shown or hidden based on another dropdown value and I need 15 copies of this page.
Right now when I copy it all the fields are the same on every page so a change on page 1 reflects on all of them, really hoping I don't have to manually rename each field 1 by 1
Is it possible once I have a page with a bunch of custom fields and JS to copy that page again with unique field names?
For example if original page has a field named "Dropdown1" the copy would create "Dropdown1_1" or something along those lines?
The reason being is I have about 50 drop downs on this one page that are shown or hidden based on another dropdown value and I need 15 copies of this page.
Right now when I copy it all the fields are the same on every page so a change on page 1 reflects on all of them, really hoping I don't have to manually rename each field 1 by 1

-
- User
- Posts: 2777
- Joined: Wed Jan 18, 2006 12:10 pm
Re: Javascript Auto Populate
Duplicating pages in combination with "Copy (fields) with Rename" should normally work via the Organize-ribbon > Duplicate Pages > Options and also when copying/duplicating pages via the Thumbnails-pane, but unfortunately that does not work correctly at this time.
It seems like a ticket to resolve that issue has been made, at the time of build 371:
viewtopic.php?t=40572
In the current latest build 383, it still does not seem to work.
@pdf-xchange support:
Can you confirm that ?
Thanks and kind regards.
It seems like a ticket to resolve that issue has been made, at the time of build 371:
viewtopic.php?t=40572
In the current latest build 383, it still does not seem to work.
@pdf-xchange support:
Can you confirm that ?
Thanks and kind regards.
-
- Site Admin
- Posts: 11802
- Joined: Wed Jan 03, 2018 6:52 pm
Re: Javascript Auto Populate
Hello, Willy Van Nuffel
The copy with rename issue was actually just fixed in our nightly build not too long ago, and will be present in the next release (build 384)!
With that said, in relation to this topic, I do not believe that we offer any way to have the javascript be updated automatically to use the new fields, so if for example, on page one you had 5 fields, and "field5" simply says " add the values of fields 1-4. Then when you duplicate the page, on page you you will see fields 6-10, but field10 would still contain JS that refers to fields 1-4, and not fields 6-9...
Kind regards,
The copy with rename issue was actually just fixed in our nightly build not too long ago, and will be present in the next release (build 384)!
With that said, in relation to this topic, I do not believe that we offer any way to have the javascript be updated automatically to use the new fields, so if for example, on page one you had 5 fields, and "field5" simply says " add the values of fields 1-4. Then when you duplicate the page, on page you you will see fields 6-10, but field10 would still contain JS that refers to fields 1-4, and not fields 6-9...
Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
PDF-XChange Co. LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
-
- User
- Posts: 2777
- Joined: Wed Jan 18, 2006 12:10 pm
Re: Javascript Auto Populate
@pdf-xchange supportTrackerSupp-Daniel wrote: ↑Wed Dec 13, 2023 9:28 pm I do not believe that we offer any way to have the JavaScript be updated automatically
Can this be something valid for a feature request ?
Kind regards.
-
- Site Admin
- Posts: 19919
- Joined: Mon Jan 12, 2009 8:07 am
Re: Javascript Auto Populate
Hello Willy Van Nuffel,
The issue here is how are we going to determine which code to update - and there could be some form fields with hundreds of lines of JS code inside in some complex form - so not really something that I can see easily automated.
Kind regards,
Stefan
The issue here is how are we going to determine which code to update - and there could be some form fields with hundreds of lines of JS code inside in some complex form - so not really something that I can see easily automated.
Kind regards,
Stefan
-
- User
- Posts: 2777
- Joined: Wed Jan 18, 2006 12:10 pm
Re: Javascript Auto Populate
Thanks for your answer Stefan.
Kind regards.
Kind regards.
-
- Site Admin
- Posts: 19919
- Joined: Mon Jan 12, 2009 8:07 am
-
- User
- Posts: 4
- Joined: Wed Dec 13, 2023 1:50 pm
Re: Javascript Auto Populate
Hey just wanted to post one last update! I got everything working now.
I was able to use the insert page option with "Copy (fields) with Rename" and then I just had to manually update the JS code on each page to the new fields which wasn't too difficult to do!
Thanks again for all your help, very much appreciated!
I was able to use the insert page option with "Copy (fields) with Rename" and then I just had to manually update the JS code on each page to the new fields which wasn't too difficult to do!
Thanks again for all your help, very much appreciated!
-
- Site Admin
- Posts: 19919
- Joined: Mon Jan 12, 2009 8:07 am
Re: Javascript Auto Populate
Hello ufc205,
Happy to hear you've got it all working as needed!
Happy holidays and
Kind regards,
Stefan
Happy to hear you've got it all working as needed!
Happy holidays and
Kind regards,
Stefan