Skip to main content
Known Participant
August 19, 2012
Question

cfmessagebox

  • August 19, 2012
  • 1 reply
  • 975 views

I am trying to use cfmessage box to confirm prior to deleting a record.  I have a delete button that I am diplaying the fessage box using onclick.  The problem I am having is the cfmessagebox pop's up, but the record gets deleted anyway and the cfmessagebox goes away.  Basically, the form is getting submitted regardless.  I am thinking I am doing something wrong here, but can someone point me in the right direction.  Below is come code snippets:

cfmessagebox code:

<cfmessagebox type="confirm" name="confirmdelete" title="Delete Employee?"

     message="Are you sure you want to delete this employee?"

     buttonType="YesNo" icon="warning" labelYes="Yes" labelNo="No">

Button code:            

<button type="submit" id="delete_button" name="delete_button" onClick="javascript:ColdFusion.MessageBox.show('confirmdelete');">Delete</button>

I am pretty sure I should change the button type to "button" rather than submit.  Then, use calbackhandler to submit the form.  However, once the form is submitted, I check for which button is pressed using:

<cfif isDefined("form.delete_button")>

I need to submit the form using javascript, then make sure, after the form is submitted, to make sure the above if statement is true.

Any ideas on what I am doing wrong?  Or, any better ways to do this?

    This topic has been closed for replies.

    1 reply

    WolfShade
    Legend
    August 20, 2012

    I think you might have answered your own question.  Changing the input from submit to button should resolve the issue.  The submit button is processing the form, regardless of what happens in the cfmessage.  Using JavaScript to submit the form is (IMHO) best.

    ^_^