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.
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:
window.alert(window.prompt("What is your name?"));
The prompt may optionally provide a placeholder:
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.