Search code examples
google-apps-scriptgoogle-sheetsinputprompt

How to check if the user didnt input any value in prompt box in Google Sheets


What can I use to know if there was no input in a prompt? Already tried the < "" > but doesnt seem to work for this case.


Solution

  • You can simply check if the response text is an empty string:

    var ui = SpreadsheetApp.getUi();
    var response = ui.prompt('Enter your name:');
    console.log(response.getResponseText()=="")
    

    if response.getResponseText()=="" is true, it means there was no input given.