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

Sandeep Rajput
Tera Patron
Tera Patron

@Naresh43 Could you please try the following and see if it works.

 

var output = g_form.getValue('guest_user_already_has_ferrero_guest_account_please_use_the_box_to_check_it');
   if(output=='true'){
    g_form.addErrorMessage('A new account is not needed.(probably the guest user manager must be updated)');
   }

 

Hope this helps.

hi @Sandeep Rajput 

 

Its not working like after giving yes option also form submitted.

i dont know what cause the isuue.

 

@Naresh43 Please update the script as follows.

 

var output = g_form.getValue('guest_user_already_has_ferrero_guest_account_please_use_the_box_to_check_it');
alert(output);
   if(output=='true'){
    g_form.addErrorMessage('A new account is not needed.(probably the guest user manager must be updated)');
   }

 

See which text shows up in alert and update the if condition accordingly.

@Naresh43 I am assuming you are using these lines inside an onSubmit script and you would like to stop the form submission if the value is yes.

 

In this case simply return false and the form submission would stop.

 

e.g.

var output = g_form.getValue('text');
   if(output=='yes'||output=='YES')){
    g_form.addErrorMessage('error message');
    return false;
   }