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.
Did you know my courses are all printer-friendly? This means you can easily export them to PDF or print them for later use.