Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

Part 2.4Basic input methods in JavaScript

Part 2.4Basic 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.

Feedback 👍
Comments are sent via email to me.