JavaScript: Confirm dialog box that shows value from a text box

Spockrates picture Spockrates · Jul 27, 2010 · Viewed 9.4k times · Source

Is there a way to have a confirm dialog box display the value a user typed in a text box on a form? (For example, if the user types 100.00, I'd like the dialog box display a message something like, "Confirm Amount. Click OK if $100.00 is the correct amount.")

Answer

spinon picture spinon · Jul 27, 2010

Yes:

var amount = document.getElementById("textbox").value;
confirm("Confirm Amount. Click OK if $" + amount + " is the correct amount.")

EDIT: Here is a working example: http://jsbin.com/inoru/edit