Copy link to clipboard
Copied
Hello, I want to create a form where a user can type a product code on a text field and show 3 other text fields which are (description of the current product code, competitor A's product, comptetitor B's product)
I've come across this tutorial and it's close to what I want to do, but instead of the drop-down I want to be able to type in the value in a text field and the relevant info would show up.
Follow up question, I have over a hundred product codes to add so I'm not sure if this is the best way to do it but I figure I'd start here, thanks
Copy link to clipboard
Copied
You can use this as 'Validate' script of 'Code' field, assuming 3 fields are named "Competitor A,B and C", just fill in 'cList' with your data nothing else needs to be changed:
var cList = [
{code: "001", cA:"Description for competitor A", cB:"Description for competitor B", cC:"Description for competitor C"},
{code: "002", cA:"Description for competitor A", cB:"Description for competitor B", cC:"Description for competitor C"},
{code: "003", cA:"Description for competitor A", cB:"Description for competitor B", cC:"Description for competitor C"}];
function updateFields(selectedCode) {
var found = false;
for (var i = 0; i < cList.length; i++) {
if (selectedCode === cList[i].code) {
this.getField("Competitor A").value = cList[i].cA;
this.getField("Competitor B").value = cList[i].cB;
this.getField("Competitor C").value = cList[i].cC;
found = true;
break;}}
if (!found) {
this.getField("Competitor A").value = "";
this.getField("Competitor B").value = "";
this.getField("Competitor C").value = "";}}
updateFields(event.value);
Copy link to clipboard
Copied
You can use this as 'Validate' script of 'Code' field, assuming 3 fields are named "Competitor A,B and C", just fill in 'cList' with your data nothing else needs to be changed:
var cList = [
{code: "001", cA:"Description for competitor A", cB:"Description for competitor B", cC:"Description for competitor C"},
{code: "002", cA:"Description for competitor A", cB:"Description for competitor B", cC:"Description for competitor C"},
{code: "003", cA:"Description for competitor A", cB:"Description for competitor B", cC:"Description for competitor C"}];
function updateFields(selectedCode) {
var found = false;
for (var i = 0; i < cList.length; i++) {
if (selectedCode === cList[i].code) {
this.getField("Competitor A").value = cList[i].cA;
this.getField("Competitor B").value = cList[i].cB;
this.getField("Competitor C").value = cList[i].cC;
found = true;
break;}}
if (!found) {
this.getField("Competitor A").value = "";
this.getField("Competitor B").value = "";
this.getField("Competitor C").value = "";}}
updateFields(event.value);
Copy link to clipboard
Copied
Hi Nesa,
This is great it worked for me (just changed Code to selectedCode)
Thank you!
Copy link to clipboard
Copied
Hi Nesa,
I've just discovered that this doesn't work on iPhone, can you please advise?
I have tested the PDF on PC and MAC and they both work fine, I type in a code on one field and the other fields are pre-polulated with texts, but for some reason the script doesn't work on iPhone.
KR
Copy link to clipboard
Copied
Hello @studiom50222188!
Thanks for reaching out. We have answered your question in the other thread you initiated: https://adobe.ly/3Zfk2v0
As stated, the current functionality you are looking for is not supported on a Mobile device with Acrobat Reader.
I hope this helps.
Thanks,
Anand Sri.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now