How to get value from choice option from form

TejasviR
Tera Contributor

Hello Everyone,

I need your help, I need to access the value of the drop-down menu which is available of form, and if the user select ABC from drop-down menu than it will compare the location and if user select XYZ then it will not.

my code:

var ch = g_form.getValue('type_of');

if (ch == "ABC"){

if (g_form.getValue('loc1') == g_form.getValue('loc2')){

g_form.addErrorMessage('Location can't be same');

}retrun false;

}

1 ACCEPTED SOLUTION

Hi,

Please use below script and see what value you get using g_form.getValue().

var ch = g_form.getValue('type_of');
alert('You have selected : '+ch);  / this will help you to get background value of Type variable.
    if (ch == "abc") {  //update this condition with value of choice ()
        if (g_form.getValue('loc1') == g_form.getValue('loc2')) {
            g_form.addErrorMessage('Location can\'t be same ');
            return false;
        }
    }

 

You might be using Label in If condition instead use value of choice 'ABC' for field type_of.

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

9 REPLIES 9

palanikumar
Mega Sage

Hi,

Can you tell me the issue you are facing with this code?

I see few issues in this code. 

1) Spelling mistake on return command

2) Return command be inside the if block.

3) You should add escape sequence before using single quotes inside a string

Hope this is written in on submit client script. So the code should be below:

function onSubmit() {
    var ch = g_form.getValue('type_of');
    if (ch == "ABC") {
        if (g_form.getValue('loc1') == g_form.getValue('loc2')) {
            g_form.addErrorMessage('Location can\'t be same ');
            return false;
        }
    }
}

 

Thank you,
Palani

Hello @palanikumar 

As I mentioned above if the user selects ABC from the drop-down menu, then my if block should be triggered else not.

 

 

Can you please share what are the choices and variable names?

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Drop down menu have 2 choice ABC & XYZ

var ch = g_form.getValue('type_of');

if (ch == "ABC"){

if(g_form.getValue('loc1') == g_form.getValue('loc2')){

g_form.addErroressage('Location cannot be same')

return false;}

}