vendredi 1 février 2019

How to use a loop that go througt checkbox and take their return value in Javascript (in a pdf)

I'm setting a form in Adobe, so i'm using Javascript directly in Adobe, and I have a problem with my loop. I've made an array of the checkbox name (Région1, Région2, etc.)

I've even tried a super-bad code with an "If" for each checkbox.
But even if I use " if (this.getField(tabRegions[i]).value != "Off")", even when the checkbox is not checked, it return either "Off" or "off" when I print regionSelect.

var tabRegions = ["Région1", "Région2", "Région3", "Région4", "Région5", "Région6", "Région7", "Région8", "Région9", "Région10", "Région11", "Région12", "Région13", "Région14", "Région15", "Région16", "Région17", "RégionTous"];

var regionSelect = "";

for (var i=0; i<= tabRegions.length; i++){
    if (this.getField(tabRegions[i]).value != "Off") {
        regionSelect = regionSelect + ", " + this.getField(tabRegions[i]).value;
    }
}

I need the value returned for each checkbox that are checked. so it should look like: "Canada, USA, Germany" if, for exemple, there is 3 checkbox that are checked.




Aucun commentaire:

Enregistrer un commentaire