Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more 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

Hope you had replaced 

v_prod & v_replace

with

i_agree & i_disagree

Yes I did.

brianlan25
Kilo Patron

To meet both your requirements of making at least one checkbox check and not both being checked.

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;
    }

}

Brian,

 

I get this error message even with 1 selected.

find_real_file.png

Looks like you have 4 check boxes.  What are the variable name for each checkbox?  It almost seems like both I Agree and I Disagree have the same variable name which should not be possible.