Skip to main content
Participating Frequently
September 20, 2023
Question

Javascript for checking boxes

  • September 20, 2023
  • 2 replies
  • 3274 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
Braniac
September 20, 2023

Use the script at calculation of the textbox.

Participating Frequently
September 20, 2023

this nothing happens

Participating Frequently
September 20, 2023

When you use checkboxes with the same name and different export values only one checkbox can be selected.


thanks Bernd that was the plan that i wanted to have 2 checkboxes both with the name checkbox 1#0 and checkbox 1#1 so that just one can be selected.

I got this as a solution:

 

// 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 check7 = this.getField("Check Box7").value;
var check8 = this.getField("Check Box8").value;
var check9 = this.getField("Check Box9").value;
var check10 = this.getField("Check Box10").value;

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

// Überprüfe, ob Checkbox 2, Checkbox 3 und Checkbox 7 gleichzeitig ausgewählt sind
if (check2 !== "Off" && check3 !== "Off" && check7 !== "Off") {
Ergebnis.value = "keine wesentliche Änderung";
} else if (check2 !== "Off" && check4 !== "Off") {
Ergebnis.value = "keine wesentliche Änderung";
} else if (check1 !== "Off" && check6 !== "Off") {
Ergebnis.value = "keine wesentliche Änderung";
} else if (check1 !== "Off" && check5 !== "Off" && check7 !== "Off") {
Ergebnis.value = "keine wesentliche Änderung";
} else if (check2 !== "Off" && check3 !== "Off" && check8 !== "Off" && check9 !== "Off") {
Ergebnis.value = "keine wesentliche Änderung";
} else if (check1 !== "Off" && check5 !== "Off" && check8 !== "Off" && check9 !== "Off") {
Ergebnis.value = "keine wesentliche Änderung";
} else if (check1 !== "Off" && check5 !== "Off" && check8 !== "Off" && check10 !== "Off") {
Ergebnis.value = "wesentliche Änderung";
} else if (check2 !== "Off" && check3 !== "Off" && check5 !== "Off" && check8 !== "Off" && check10 !== "Off") {
Ergebnis.value = "wesentliche Änderung";
} else {
// Wenn keine der oben genannten Bedingungen erfüllt ist, leere das Textfeld
Ergebnis.value = "";
}

 

Guess its easier than getting checkboxes with exclude the other

try67
Braniac
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
Braniac
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"; }