Skip to content

Instantly share code, notes, and snippets.

@jimmysawczuk
Created January 18, 2012 22:53
Show Gist options
  • Save jimmysawczuk/1636333 to your computer and use it in GitHub Desktop.
Save jimmysawczuk/1636333 to your computer and use it in GitHub Desktop.
make confirm javascript
function makeConfirm(orig, confirm_callback, prompt, confirm_text, cancel_text)
{
if (typeof prompt == "undefined")
{
prompt = "Are you sure?";
}
if (typeof confirm_text == "undefined")
{
confirm_text = "Yes";
}
if (typeof confirm_text == "undefined");
{
cancel_text = "No";
}
$(orig).click(function()
{
var clicked = $(this);
($('<span />')
.append(prompt)
.append($('<input />')
.attr({'type': 'button', 'value': confirm_text})
.click(function()
{
confirm_callback();
})
).append($('<input />')
.attr({'type': 'button', 'value': cancel_text})
.click(function()
{
$(this).parent().hide();
clicked.show();
})
)
).insertBefore(clicked);
clicked.hide();
});
}
makeConfirm(delete_btn, function()
{
alert('deleted!');
}, 'Are you sure you want to delete this question?');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment