Wednesday, May 27, 2009

Javascript Confirmation Dialog

I was trying to get verification from the user on a delete command. This may not be the correct solution.

I needed a button, when the user clicks, a pop-up form asking "Are you sure?" appears. If the user selects 'Cancel', nothing happens. If the user selects 'Ok', then the data is deleted.

I developed this solution:



I am using the submit, because I have a hidden field that is set with a value depending on what the user has chosen to do. This is the reason for doing nothing on 'ok' and something on 'cancel'.


*************************************************
11/25/2009

I think this is a more versatile solution.

//***************************************************
// Name: Form Submit
// Parameter [formId] : this is the Id of the form to
// submit.
// Parameter [verify] : 'true' if the form needs a
// confirmation before submitting, any other string
// if the form does not need confirmation.
// Parameter [message] : Message to show if the form
// needs validation.
//**************************************************
function formSubmit(formId, verify, message) {
if (verify == "true") {
if (confirm(message)) {
document.getElementById(formId).submit();
}
}
else {
document.getElementById(formId).submit();
}
}

No comments:

Post a Comment