User Input - confirm and prompt

Published on: August 12, 2016

Welcome to the eighth Easy JavaScript Tutorial, Beginner JavaScript Tutorial, part of Easy Programming! Thus far, I've covered how to output data. In this tutorial, we're going to look at two ways you can ask your user for input. Essentially taking your web application from Web 1.0 to Web 2.0 by making it interactive. 

The most practical way to ask for input is usually through form elements. This is something we'll cover in a future tutorial. Today, we're going to cover two built in methods (or functions) of the Window object. They are confirm() & prompt().

confirm() is a method of the window object which allows you to ask the user to confirm their choice, either okay (true) or cancel/close (false). You can then use the boolean input to trigger functions and other actions within your script.

prompt() is another method of the window object which allows you to prompt the user for an input. You can store the data into a variable, manipulate it, and output it any way and anywhere you'd like.

To fork the fiddle and follow along: https://jsfiddle.net/cqcs72Lw/

Remember to checkout the Resources section below for associated downloadable content, JSFiddle links, and other resources. Watch the video and follow along!

Resources:



Comments: