Skip navigation
sfriedman426
Currently Being Moderated

Check for a response among check boxes in a "check all that apply" selection group

May 3, 2012 4:07 PM

Tags: #box #check #groups

There are a few check box fields on my form that ask "check all that apply". For this reason I must assign a unique field name to each check box so that they are named sequentially resp1, resp2, etc. I want to check to ensure that the user has checked at least one response from this group. Is there a way to do this?

 
Replies
  • George Johnson
    9,232 posts
    Aug 11, 2002
    Currently Being Moderated
    May 3, 2012 8:33 PM   in reply to sfriedman426

    Sure, you just have to check the fields in sequence, and if the value is not "Off", you can stop looking. For example, if there are ten check boxes in your group, the code might look something like:

     

     

    // Initialize variable
    var bChecked = false;
    
    // Loop through the check boxes
    for (var i = 1; i < 11; i += 1) {
    
        if (getField("resp" + i).value !== "Off") {
    
            // Indicate that at least one is checked
            bChecked = true;
    
            // No need to keep looking
            break;
        }
    }
    
    // true if at least one is checked, false if none are checked
    app.alert(bChecked);
    
    
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points