To use this website fully, you first need to accept the use of cookies. By agreeing to the use of cookies you consent to the use of functional cookies. For more information read this page.

Basic input methods in JavaScript

After covering the output methods of JavaScript, this article will cover the input methods of JavaScript.

Confirm dialog

The confirm dialog is a simple yes or no dialog and can be used to 'confirm' that a user wishes to proceed.

JavaScript
window.confirm("Do you wish to continue?");

Prompt dialog

If user input needs to be more than an OK or Cancel, the prompt dialog can be used. A prompt dialog provides the user with a textbox that allows them to input a response to the dialog:

JavaScript
window.alert(window.prompt("What is your name?"));

The prompt may optionally provide a placeholder:

JavaScript
window.alert(window.prompt("What is your name?", "Jamie Balfour"));

As with the alert method, both confirm and prompt are methods provided by the window and do not need window. in front of them.

Provide feedback on this page
Comments are sent via email to me.