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

stuck on a function

Bradley Bush
Mega Sage

Hi, I have a form that needs to produce an error when a checkbox is not checked, I got that to function. I need it to only operate if another yes/no variable is answered yes, this is where i'm stuck.  thank you

function onSubmit() {
    // Check if the checkbox 'cl_ctx_app' is not checked (assuming 'false' means not checked)
    if (g_form.getValue('cl_ctx_app') == 'false') {
        // If not checked, show an error message next to the checkbox field
        g_form.showFieldMsg('cl_ctx_app', 'You must check the CTX APP Access checkbox', 'error');
        // Return false to prevent form submission
        return false;
    }
    // If the checkbox is checked (value is not 'false'), the form submission will proceed
}

 

1 ACCEPTED SOLUTION

Saloni Suthar
Mega Sage
Mega Sage

Hi @Bradley Bush ,

Please see script below

function onSubmit() {
    // Check if the other Yes/No variable is answered "Yes", change the variable name to match yours
    if (g_form.getValue('other') == 'Yes') {
        // If 'other_variable' is "Yes", proceed to check 'cl_ctx_app' checkbox
        if (g_form.getValue('cl_ctx_app') == 'false') {
            // If 'cl_ctx_app' checkbox is not checked, show an error message
            g_form.showFieldMsg('cl_ctx_app', 'You must check the CTX APP Access checkbox', 'error');
            // Return false to prevent form submission
            return false;
        }
    }
    // If 'other_variable' is not "Yes" or 'cl_ctx_app' is checked, the form submission will proceed
}

If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni

View solution in original post

2 REPLIES 2

Saloni Suthar
Mega Sage
Mega Sage

Hi @Bradley Bush ,

Please see script below

function onSubmit() {
    // Check if the other Yes/No variable is answered "Yes", change the variable name to match yours
    if (g_form.getValue('other') == 'Yes') {
        // If 'other_variable' is "Yes", proceed to check 'cl_ctx_app' checkbox
        if (g_form.getValue('cl_ctx_app') == 'false') {
            // If 'cl_ctx_app' checkbox is not checked, show an error message
            g_form.showFieldMsg('cl_ctx_app', 'You must check the CTX APP Access checkbox', 'error');
            // Return false to prevent form submission
            return false;
        }
    }
    // If 'other_variable' is not "Yes" or 'cl_ctx_app' is checked, the form submission will proceed
}

If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni

Bradley Bush
Mega Sage

thank you so much just what i needed:)