Skip to main content
Participating Frequently
September 20, 2023
Question

Javascript for checking boxes

  • September 20, 2023
  • 2 replies
  • 3308 views

Hi everyone,

 

i got a pdf and want to let a textbox get deceided by checkboxes in front.

i got 5 questions where you can answer yes / no with 1 checkbox for every question:

 

The textbox should say "keine wesentliche Änderung" in those cases:

1. if checkbox 1 is a no + checkbox 2 is a no

2. if checkbox 1 is a no, checkbox 2  is a yes, checkbox 4 a yes

3. if checkbox 1 is a no, checkbox 2  is a yes, checkbox 4 a no + checkbox 5 a yes

 

The textbox should say "wesentliche Änderung" in those cases:

4. if checkbox 1 is a yes + checkbox 3 a no

5. if checkbox 1 is a yes + checkbox 3 a yes + checkbox 4 a yes

6. if checkbox 1 is a yes + checkbox 3 a yes + checkbox 4 a no + checkbox 5 a no

 

i tried to get the value with this.getField().value but it didnt work.

 

TIA Tim

This topic has been closed for replies.

2 replies

Bernd Alheit
Community Expert
Community Expert
September 20, 2023

Use the script at calculation of the textbox.

Participating Frequently
September 20, 2023

this nothing happens

Bernd Alheit
Community Expert
Community Expert
September 20, 2023

Any error in the console?

try67
Community Expert
Community Expert
September 20, 2023

> i tried to get the value with this.getField().value but it didnt work.

 

That should have worked (assuming you specified the field name as the parameter of getField)... A check-box group will have the value "Off" if no box is selected, or the export value of the selected box. What happened when you used that code?

Participating Frequently
September 20, 2023

the code is:

 

// Definition von Variablen

var check1 = this.getField("Check Box1").value;
var check2 = this.getField("Check Box2").value;
var check3 = this.getField("Check Box3").value;
var check4 = this.getField("Check Box4").value;
var check5 = this.getField("Check Box5").value;
var check6 = this.getField("Check Box6").value;

var Ergebnis = this.getField("Ergebnis").value;

// Anweisung

if
(check1 !== "Off" && check2 !== "Off") {
Ergebnis = "keine wesentliche Änderung"; }

 

nothing happened in textbox "ergebnis"

try67
Community Expert
Community Expert
September 20, 2023

OK, that's because you're not applying the value correctly. Once you copy the value to a variable it's just a string, unattached to the field. Change the last lines to this:

 

var Ergebnis = this.getField("Ergebnis");

// Anweisung

if (check1 !== "Off" && check2 !== "Off") {
Ergebnis.value = "keine wesentliche Änderung"; }