Skip to main content
Participant
August 2, 2025
Question

Can't get simple JS to show a text in 4 textfields from a dropdown i dont know if i made a error

  • August 2, 2025
  • 1 reply
  • 307 views

i have added my PDF

DropdownAMHL has 3 different  case it wont show the text in

 

RD1RD2

RD3RD4

motorpasser

RD5RD6

 

my JS is in RD1RD2

// Hvis der sker en event i dropdownens værdi
if(event.source&&event.source.name == "DropdownAMHL")
event.value == this.getField("DropdownAMHL").value;

// Hent dropdownens værdi
var dropdown60Value = this.getField("DropdownAMHL").value;

switch (dropdown60Value) {

case "3":
this.getField("RD1RD2").value = "RD1";
this.getField("RD3RD4").value = "RD2";
this.getField("motorpasser").value = "Motorpasser";
this.getField("RD6RD7").value = "";
break;

case "5":
this.getField("RD1RD2").value = "RD1\nRD2";
this.getField("RD3RD4").value = "RD3\nRD4";
this.getField("motorpasser").value = "Motorpasser";
this.getField("RD6RD7").value = "";
break;

case "7":
this.getField("RD1RD2").value = "RD1\nRD2";
this.getField("RD3RD4").value = "RD3\nRD4";
this.getField("motorpasser").value = "Motorpasser";
this.getField("RD6RD7").value = "RD6\nRD7";
break;
}

also tried to put it in DropdownAMHL an remove it from 

RD1RD2

and that is the same all the others work fine 

 

1 reply

Nesa Nurani
Community Expert
Community Expert
August 2, 2025

Remove that script from "RD1RD2" field and put this script under 'Validate' tab of "DropdownAMHL" field:

switch (event.value) {

case "3":
   this.getField("RD1RD2").value = "RD1";
   this.getField("RD3RD4").value = "RD2";
   this.getField("motorpasser").value = "Motorpasser";
   this.getField("RD6RD7").value = "";
break;

case "5":
   this.getField("RD1RD2").value = "RD1\nRD2";
   this.getField("RD3RD4").value = "RD3\nRD4";
   this.getField("motorpasser").value = "Motorpasser";
   this.getField("RD6RD7").value = "";
break;

case "7":
   this.getField("RD1RD2").value = "RD1\nRD2";
   this.getField("RD3RD4").value = "RD3\nRD4";
   this.getField("motorpasser").value = "Motorpasser";
   this.getField("RD6RD7").value = "RD6\nRD7";
break;
}
Participant
August 2, 2025

Well I did try that also before I posted to get help in have another dropdown with another JS where it it also a simple js code where it works but will try without 

 

// Hvis der sker en event i dropdownens værdi
if(event.source&&event.source.name == "DropdownAMHL")
event.value == this.getField("DropdownAMHL").value;

// Hent dropdownens værdi
var dropdown60Value = this.getField("DropdownAMHL").value;

 

I also have another question if I use it on my phone then make an selection from one of the dropdownbox then nothing happens at first but at the second time it show the textfields changes

Is there a script that does that it the background to run js when pdf is open the first time on a phone I have no problem on a laptop I have olso tried to optimise the pdf but that the same

try67
Community Expert
Community Expert
August 2, 2025

Change this:

event.value == this.getField("DropdownAMHL").value;

To:

event.value = this.getField("DropdownAMHL").value;

 

The last line of your code does nothing.