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!