Not signed in (Sign In)

Vanilla 1.1.5a is a product of Lussumo. More Information: Documentation, Community Support.

  1.  
    I'm looking for some JavaScript to see if 2 checkboxes are checked and if so a error message can be displayed. I can not use bullets due to a text section between the 2 checkboxes. I haven't been able to find what I need. Any suggestions?
    • CommentAuthordbuschho
    • CommentTimeFeb 26th 2010
     
    Which form are you working with martin?
  2.  
    http://www.tfaforms.com/143879

    This is a test form to see if I could figure out how to do it. Once I see the method, I can transpose it to the working form. You can see how I tried to use a text field as a validator of sorts and used regex to check for the error. What would be ideal is to do something like the email validation code:
    http://www3.formassembly.com/forum/discussion/60/email-validation/#Item_4
    but in this case just check to see if both checkboxes are checked. I hope this makes sence.
    • CommentAuthordbuschho
    • CommentTimeMar 1st 2010
     
    Here's something to get you started. It takes the parent element of a set of checkboxes ( have to find that by inspecting the html code, should be of class 'choices' ), then grabs all the checkboxes in that set, and loops through looking for any empty ones.

    If it finds an empty one, it stops and displays error message
    otherwise, passes.

    Points of failure:
    1. Can't set specific number of checkbox choices
    2. Would need a fair bit more code to work with multiple different sets of checkboxes.

    Demo here: http://app.formassembly.com/144790

    <script type="text/javascript">
    var fieldId = "tfa_3042554300553";

    wFORMS.behaviors.validation.messages['isAllChecked'] = "All checkboxes aren't checked.";

    // leave the rest as is.
    wFORMS.behaviors.validation.rules['isAllChecked'] = { selector: "#"+fieldId,
    check: function(element) {
    var c=document.getElementById(fieldId);

    var _continue = true;

    base2.DOM.Element.querySelectorAll(c,"input[type='checkbox']").forEach(function(item){

    if(_continue){
    if(item.checked == false){
    _continue = false;
    }
    }

    });

    return _continue;
    }};
    </script>