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

How to populate a field using a radio button option

F_bio Santos
Kilo Sage

Hi everyone, Im trying to set a value of a field "Confidentiality" depending on 3 radio buttons on a record producer, the buttons are: 

"Public" -> Choices: "yes"
"Confidential" -> Choices: "yes"
"Restricted" -> Choices: "yes"

When I click one of the buttons it clears the value of the others, what Im trying to do is if the person chooses for exemple "Public", the field "Confidentiality" will be "Public" I've tried with this code:


 

 

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var publicOption = g_form.getValue('public_option1');
    var confidentialOption = g_form.getValue('confidential_option1');
    var restrictedOption = g_form.getValue('restricted_option1');

    var confidentialityField = 'u_confidentiality';

    if (publicOption == 'sim') {
        confidentialityField = 'public';
    } else if (confidentialOption == 'sim') {
        confidentialityField = 'confidential';
    } else if (restrictedOption == 'sim') {
        confidentialityField = 'highly_confidential';
    }
}

 

 


But the the "Confidentiality" field always comes with the value "Public" does anybody knows why ?

F_bioSantos_0-1694689795582.png

 

1 ACCEPTED SOLUTION

F_bio Santos
Kilo Sage

I changed the code to this and it worked

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var publicOption = g_form.getValue('public_option1');
    var confidentialOption = g_form.getValue('confidential_option1');
    var restrictedOption = g_form.getValue('restricted_option1');

    var confidentialityField = 'u_confidentiality';

    if (publicOption == 'sim') {
        g_form.setValue(confidentialityField, 'public');
    } else if (confidentialOption == 'sim') {
        g_form.setValue(confidentialityField, 'confidential');
    } else if (restrictedOption == 'sim') {
        g_form.setValue(confidentialityField, 'highly_confidential');
    }
}

View solution in original post

3 REPLIES 3

Manisha Reddy K
Mega Guru

Hi @F_bio Santos ,

      Can you alert the values of publicOption,confidentialOption,restrictedOption and see what values are returned after submission.

Hi @Manisha Reddy K just checked and they are all coming as "false" even the one I choose

 

F_bio Santos
Kilo Sage

I changed the code to this and it worked

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var publicOption = g_form.getValue('public_option1');
    var confidentialOption = g_form.getValue('confidential_option1');
    var restrictedOption = g_form.getValue('restricted_option1');

    var confidentialityField = 'u_confidentiality';

    if (publicOption == 'sim') {
        g_form.setValue(confidentialityField, 'public');
    } else if (confidentialOption == 'sim') {
        g_form.setValue(confidentialityField, 'confidential');
    } else if (restrictedOption == 'sim') {
        g_form.setValue(confidentialityField, 'highly_confidential');
    }
}