Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,151,501 members, 7,812,552 topics. Date: Monday, 29 April 2024 at 03:13 PM

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

Nairaland Forum / Science/Technology / Programming / How To Create A Confirm Box In Javascript (1927 Views)

Functional Programming In Javascript / Pattern Chaser In Javascript: Coding Challenge / Cookie Programming In Javascript (2) (3) (4)

(1) (Reply)

How To Create A Confirm Box In Javascript by nateone(m): 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)

Please Help With This Fortran Assignment / MMM Calculator (mavro) - Android App / Studying Computer Science At 40?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 7
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.