admin管理员组

文章数量:1293740

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

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

Share asked Jul 27, 2010 at 16:17 SpockratesSpockrates 751 gold badge5 silver badges14 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

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./inoru/edit

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

You should check the onblur event from the textbox, if the textbox is not empty then show the message, sth like this:

document.getElementById('textboxid').onblur = function(){
    if(this.value.length > 0 )
        showApplicationMessage()
}

本文标签: JavaScript Confirm dialog box that shows value from a text boxStack Overflow