The CreatorCon Call for Content is officially open! Get started here.

Only 1 checkbox can be checked

John Vo1
Tera Guru

I have this client script that should only allow 1 checkbox to be selected, but when I test it still lets me select I agree or I disagree.  Can someone help me out?

find_real_file.png

1 ACCEPTED SOLUTION

Another thought is to possibly just ask if they Agree and then have a Yes/No drop down or if it is important that they choose agree or disagree use a multi-Choice box.  Both these options could be made mandatory unlike check boxes and they can only chose one.  Example of a multi-choice field.

find_real_file.png

You could also use a select box with options I Agree or I Disagree.

View solution in original post

17 REPLIES 17

the 2nd check box is i_agree_1 and i_disagree_1.

I'm not sure how my code could be causing that.  I should be only looking at the one set of check boxes.  Did you change it in any way to make it look at all 4?

No I copy and paste your script in.  

 

1st check box variable names :  i_agree and i_disagree

2nd check box variable names:  i_agree_1 and i_disagree_1.

 

Thanks,

John

function onSubmit() {
    //Type appropriate comment here, and begin script below
    if (g_form.getValue('i_agree') == 'true' && g_form.getValue('i_disagree') == 'true') {
        alert('You can only select one option');
        return false;
    } else if (g_form.getValue('i_agree') == 'false' || g_form.getValue('i_disagree') == 'false') {
        alert('you must select an option');
        return false;
    }

}

Ok I just created a simple form in my PDI with 4 check boxes.  I made the display name almost the same as the variable name except no user scores between letters.
find_real_file.png

I used the following code and it works without issues.

function onSubmit() {
    //Type appropriate comment here, and begin script below
    if (g_form.getValue('i_agree') == 'true' && g_form.getValue('i_disagree') == 'true') {
        alert('you can only choose one option first set of checkboxes');
        return false;
    } else if (g_form.getValue('i_agree') == 'false' && g_form.getValue('i_disagree') == 'false') {
        alert('you must choose one option first set to checkboxes');
        return false;
    } else if (g_form.getValue('i_agree_1') == 'true' && g_form.getValue('i_disagree_1') == 'true') {
        alert('you can only choose one option second set of checkboxes');
        return false;
    } else if (g_form.getValue('i_agree_1') == 'false' && g_form.getValue('i_disagree_1') == 'false') {
        alert('you must choose one option second set to checkboxes');
        return false;
    }
}