简体   繁体   中英

Trying to have a checkbox automatically check 2 other checkboxes

I'm very new to coding in java... So I apologize for the seemingly simple question.

However, In an Adobe PDF Form, I have a list of seven checkboxes, and when I select checkbox 2,3,or 4 I would like two other checkboxes to either be highlighted or selected.

So if Box B "r2w_att_B" is checked then "r2w_min_cond1" and "r2w_min_cond2" should both be checked. and if the form filler decides to check those boxes before selecting B,C or D then nothing should change. basically it is to ensure that you can't select B,C or D and "forget" to select the 2 minimum conditions.

and the same would be true for box C and D, so in theory the code should be the same with the exception of name of the initial box, I've used this line from another part of the form and it worked. so I could use that again. [if (event.target.value == "Yes")]

I have no idea how to write this... and the other code snippets I came across, I don't quite understand and cant make them work. I did piece together a clip of functional code, that on "mouse up" a checkbox triggers a textbox to copy "value" to another text box.

I appreciate anyone and everyone's guidance as I start learning a Java

You can do something like this:

 var checkbox1 = document.getElementById("ck1"); var checkbox2 = document.getElementById("ck2"); var checkbox3 = document.getElementById("ck3"); checkbox1.addEventListener('change', function() { checkbox2.checked = this.checked; checkbox3.checked = this.checked; });
 < DOCTYPE html> <html> <body> <input type="checkbox" id="ck1" name="ck1" value="Checkbox1"> <label for="vehicle1"> Checkbox 1</label><br> <input type="checkbox" id="ck2" name="ck2" value="Checkbox2"> <label for="vehicle2"> Checkbox 2</label><br> <input type="checkbox" id="ck3" name="ck3" value="Checkbox3"> <label for="vehicle3"> Checkbox 3</label><br><br> <input type="checkbox" id="ck4" name="ck4" value="Checkbox4"> <label for="vehicle3"> Checkbox 4</label><br><br> </body> </html>

if (event.target.value!="Yes")
{getField("firstchkbox").value = "Yes";
getField("secondchkbox").value = "Yes";  }

This is ultimately how I got it to work in Adobe.
on mouse down, it executes a Javascript, and checks the two boxes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM