JavaScript: validate dialog box displaying value from text field

Is there a way for the confirmation dialog to display the value entered by the user in the form text box? (For example, if the user enters 100.00, I would like the message “Confirm Amount” to appear in the dialog box. Click “OK” if $ 100 is the correct amount.)

+3
source share
3 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

+4
source

Of course, you can simply pass the string value in the dialog box:

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

, , . :

var amount = jQuery("#myTextBox").val();
confirm("Click OK if " + amount + " is the correct amount");
+1

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

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

Source: https://habr.com/ru/post/1756774/


All Articles