I am trying get the response of the user to do another action.
Browser.msgBox('Greetings', 'hello world', Browser.Buttons.YES_NO);
if (response == Browser.Buttons.YES) {
Logger.log('The user clicked "Yes."');
} else {
Logger.log('The user clicked "No" or the dialog\'s close button.');
}
but this does not work. "response is not defined" error shows up. How do I get the response?
Take a closer look at the documentation. It returns a String containing the "lower case text of the button that is clicked by the user (or 'cancel' for a dismissed dialog)".
You also need to save the return value in the response
variable.
var response = Browser.msgBox('Greetings', 'hello world', Browser.Buttons.YES_NO);
if (response == "yes") {
Logger.log('The user clicked "Yes."');
} else {
Logger.log('The user clicked "No" or the dialog\'s close button.');
}
This is how it works :
var response = Browser.msgBox('Greetings', 'hello world', Browser.Buttons.YES_NO);
Logger.log(response);
if (response == "yes") {
Logger.log('The user clicked "Yes."');
} else {
Logger.log('The user clicked "No" or the dialog\'s close button.');
}
Browser method that ask for a response option returns a string, you could have used the logger like in the code above to check it. So we have to use a condition on that string to check the result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With