Skip to main content
December 2, 2016
Question

Need dropdown fields to populate checkbox (Yes, No)

  • December 2, 2016
  • 1 reply
  • 394 views

My customer has a form with a Checkbox field called "WeekendCare" With options "Yes" and "No" 

I have 8 dropdown fields (Weekend open and close times) that will need to be examined to determine whether to populate the yes/no. If ANY of the following 8 dropdown fields have a value of a time in the dropdown (other than the default "Select") - the Weekend Care gets checked "Yes"  - if none have values, then "No" is checked.

The dropdown fields are named:

CenterOpenSaturday

CenterOpenSaturday2

CenterCloseSaturday

CenterCloseSaturday2

CenterOpenSunday

CenterOpenSunday2

CenterCloseSunday

CenterCloseSunday2

Can you help with a javascript for this?

And please let me know which field to place the javascript in... that is confusing sometimes.

Thanks for your help!

This topic is closed to new replies. Start a new post to keep the conversation going.

1 reply

try67
Community Expert
Community Expert
December 2, 2016

Yes, this kind of operation can be quite tricky. I think the best was of doing it is to create a hidden text field and use its calculation event for this task, even if the field itself has nothing to do with it. You can use this code to achieve it:

var dropdowns = [

    "CenterOpenSaturday", "CenterOpenSaturday2", "CenterCloseSaturday", "CenterCloseSaturday2", "CenterOpenSunday", "CenterOpenSunday2", "CenterCloseSunday", "CenterCloseSunday2"

];

var tickBox = false;

for (var i in dropdowns) {

    var f = this.getField(dropdowns);

    if (f.valueAsString!=f.defaultValue) {

        tickBox = true; break;

    }

}

this.getField("WeekendCare").checkThisBox(0, tickBox);