₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,948 members, 8,424,298 topics. Date: Wednesday, 10 June 2026 at 11:33 PM

Toggle theme

How To Create A Confirm Box In Javascript - Programming - Nairaland

Nairaland ForumScience/TechnologyProgramming How To Create A Confirm Box In Javascript (2011 Views)

1 Reply

How To Create A Confirm Box In Javascript by nateone(op): 2:51pm On Jul 21, 2008
Confirm boxes are a convenient way to give a web visitor a simple choice: to accept or to decline something. They are displayed using the JavaScript confirm function.
Create a Confirm Box in JavaScript
Step1
Write the code to call the confirm function, following the example below. The result from confirm is placed in the variable ok so it can be tested in subsequent logic.
ok = confirm("Do you really want to do this?"wink;
Step2
Concatenate strings using the "+" operator to display a message made up of several parts, as follows:
ok = confirm ("Are you really " + age + " years old?"wink;
Step3
Test the value returned from the confirm function and take the appropriate action. In the following example, if the user presses the Cancel button he or she is returned to the previous page. (The exclamation point is the Boolean NOT operator, which changes true to false and false to true, so a return value of false, corresponding to the user pressing Cancel, is converted to true, which passes the if test.)
if (!ok) { history.back (); }


# f you don't need to give the user the option to Cancel, consider using the alert function instead.
# Instead of storing the result from confirm in a variable and testing it, you can test it directly within an ifstatement with a construct such as if (confirm(, ) { }.
# Technically the confirm function is a method on the JavaScript window object, and thus could be written window.confirm, but since JavaScript on web pages is executed within the context of the window object anyway, this is not necessary.

www.flyhow..com
1 Reply

Functional Programming In JavascriptPattern Chaser In Javascript: Coding ChallengeCookie Programming In Javascript234

Browse For Free Without LimitRecommend A Laptop For Me Bw 50-60kHelp A Friend To Learn Java, Php, C#, C And C++