Confirm

From codeTank

Revision as of 01:20, 9 December 2007 by Sean (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Contents

Description

confirm is a function used to confirm an action in a simple popup window.

Arguments

confirm(text) -- title defaults to "Confirm"
confirm(text, title)

confirm only takes one or two arguments. It applies tostring to each argument if it isn't already a string. The first argument is the text to be displayed in the confirmation window. If a second argument is present, then it's used to set the title of the window. If the second argument is omitted, then the default title is "Confirm".

Returns

confirm returns true for a user clicking on Yes, false for a user clicking on No, or nil for a user clicking on Cancel or closing the window.

Example

if (confirm("Want to see a popup window?")) then
    alert("Here you go... pretty fantastic, huh?")
end

res = confirm("Save changes to Untitled?", "What do you want to do?")
if (res) then
    alert("Saving the changes...")
elseif (res == false) then
    alert("Ok... I will discard the changes")
else
    alert("Canceling this entire action")
end

See Also