Create an InputBox with Google Apps Script

Google Sheets allows you to display a dialog box asking the user to enter information, which you can then retrieve in a variable.


Simple Dialog Box

You can display a dialog box and retrieve the entered text using:

function example() {
  const name = Browser.inputBox('Enter your name:');
}

google sheets inputbox

Dialog Box with Title and Cancel Button

You can also set a title and modify the buttons:

function example() {
  const name = Browser.inputBox('Registration', 'Enter your name:', Browser.Buttons.OK_CANCEL);
}

google apps script inputbox

The variable name will receive the value entered by the user (or the text value cancel if clicking Cancel).

Prompt Dialog Box

An alternative (recommended by Google) to using Browser.inputBox which also allows you to display dialog boxes and more efficiently retrieve the text and the clicked button is prompt (more information on this method).