Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.")

like image 840
Spockrates Avatar asked Oct 14 '25 14:10

Spockrates


2 Answers

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

like image 164
spinon Avatar answered Oct 17 '25 10:10

spinon


Sure, you can just pass a string value to the dialog:

var str = "my msg";
confirm(str);

So to display your custom message, just get the value of the text box and append it to your message. For example:

var amount = jQuery("#myTextBox").val();
confirm("Click OK if " + amount + " is the correct amount");
like image 33
Justin Ethier Avatar answered Oct 17 '25 10:10

Justin Ethier