11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

window.confirm(string);<br />

or simply<br />

confirm(string);<br />

where string is any valid string variable, literal, or expression that eventually evaluates to a<br />

string value to be used as the confirmation question.<br />

<strong>The</strong> confirm() method returns a Boolean value that indicates whether or not the information<br />

was confirmed, true if the OK button was clicked and false if the window was closed or the<br />

Cancel button was clicked. This value can be saved to a variable, like so<br />

answer = confirm("Do you want to do this?");<br />

or the method call itself can be used within any construct that uses a Boolean expression such<br />

as an if statement, like the one here:<br />

if (confirm("Do you want ketchup on that?"))<br />

else<br />

alert("Pour it on!");<br />

alert("Hold the ketchup.");<br />

Like the alert() method, confirmation dialogs should be browser modal.<br />

<strong>The</strong> next example shows how the alert and confirm can be used.<br />

<br />

<br />

<br />

<strong>JavaScript</strong> Power!<br />

<br />

<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!