The affirm() is mainly a technique, which is used to point out a pop-up field over the online web page, and it accommodates a message or textual content and two buttons, “OK” & “Cancel”. On the press of the “OK” button, the affirm methodology returns “true”. Equally, on the press of the “Cancel” button, it returns false.
There are two totally different syntaxes for displaying the affirm field. One in every of them is utilizing the window’s object
However, we are able to use the affirm() methodology with out the window’s object as nicely.
On this syntax, the message will be any string or a variable that may embrace a message.
So, let’s strive each of the syntaxes.
First, let’s strive with the window’s object
window.affirm(“Verify message from Linuxhint”);
And now with out window’s object
affirm(“Verify message from Linuxhint”);
You’ll witness that there isn’t a distinction in each of them.
The affirm methodology doesn’t solely take the string to point out the message. We will present variable as nicely, and it labored completely nice.
var confirmMessage = Verify Message utilizing variable’;
As you may see within the screenshot beneath that the message is displayed.
We now have discovered about offering a variable as nicely. What if we need to present the pop-up alert field on the display screen on the click on of a button. For instance, now we have received some info from the consumer, and after efficiently saving the consumer’s information on the server, we need to present a affirmation message that “Confirmed”. So, we are able to merely present a affirmation field like this.
Or if we’re getting a affirmation message from the server, and we need to present the message on the bottom of the message we received. We will name the operate on the button’s onClick methodology.
And later within the script, we are able to write the operate wherein we are able to present the affirmation message.
So, these are among the totally different strategies of utilizing the affirm() methodology.