Need to though an error message

Naresh43
Tera Contributor

Hi All,

I have created a field called "text" as a yes/no kind of variable so, when user selects the text as yes then we i have through an error meassge.

i have created like this onChange client script field as text 

its not working as expected can someone help me here ..

 

var output = g_form.getValue('text');
   if(output=='YES'){
    g_form.addErrorMessage('error message)');
   }
 
Regards,
Naresh
   
2 ACCEPTED SOLUTIONS

Maddysunil
Kilo Sage

@Naresh43 

Please validate the backend name of your choices inside dictionary of 'text' field. I am assuming Yes as true and no as false. Below is the script:

 

function onChangeText() {
    var output = g_form.getValue('text');
    if (output == 'true') {
        g_form.addErrorMessage('Error message: You selected "Yes" for the text field.');
    } else {
        g_form.clearMessages(); // Clear any existing error messages
    }
}

 

  

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

 

View solution in original post

@Naresh43 

Form does'nt get submitted for onchage client script, Try using on submit client script.

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

 

View solution in original post

16 REPLIES 16

@Naresh43 

Please use below code:

 

    var output = g_form.getValue('text');
    if (output == 'true') {
        g_form.addErrorMessage('Error message: You selected "Yes" for the text field.');
        return false; // Prevent form submission
    } else {
        g_form.clearMessages(); // Clear any existing error messages
    }

 

  

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

 

hi @Maddysunil 

 

i have applied the same logic but its submitting the form after error message came 

Suggest me something please

@Naresh43 

Could you please share your script 

Hello @Maddysunil 

 

I have user the bellow code with onchage client script on that field 

var output = g_form.getValue('guest_user_already_has_guest_account_please_use_the_box_to_check_it');
   if(output=='YES'){
    g_form.addErrorMessage('A new account is not needed.(probably the guest user manager must be updated)');
    return false;
   }
    else{
    g_form.clearMessages();
    }
   

@Naresh43 

Form does'nt get submitted for onchage client script, Try using on submit client script.

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks