Solved

customized confirmation message box

Posted on 2012-03-09
8
745 Views
Last Modified: 2012-03-11
I have a customized confirmation message box that pops up when a cfform is submitted.  My code is below.  My problem is the code doesn't wait for the user to confirm the submission.  The message box pops up temporarily and then the form is submitted without the user selecting a button.



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
 
<script  type="text/javascript">
    //Function to show results of other message boxes.
    var showResult2 = function(btn){
            if (btn == 'yes'){
        alert("You clicked Agree button: "+btn);
            }
            else{
        alert("You clicked Cancel button: "+btn);
            }
    }
 
    //The button onClick handler displays the message boxes.
    function showMB(mbox)  {
        ColdFusion.MessageBox.show(mbox);
    }
</script>
</head>
 
<body>
<cfform name="dg" action="test.cfm">
    <p>Click a button display the corresponding message box.</p>
    <cfinput name="Prompt" type="submit" value="Submit" onclick="showMB('mymessagebox02')">
</cfform>
 
<!--- Code to define the message boxes. --->                    
<cfmessagebox name="mymessagebox02" bodystyle="font-family: Arial, Helvetica, sans-serif" type="confirm" title="Warning:"  
        message="Are you sure you want to proceed?"  
        labelNO="Cancel" labelYES="Agree"
        callbackhandler="showResult2"/>
 
     
</body>
</html>
0
Comment
Question by:curtis247
  • 3
  • 3
  • 2
8 Comments
 
LVL 39

Expert Comment

by:gdemaria
ID: 37702744
The problem is that you are actually submiting the form with your input tag called "Prompt".. that should be changed from type submit to type button.

Then in your pop up message, when the user agrees, that button press action should submit the form..
0
 

Author Comment

by:curtis247
ID: 37703649
Changing the input type to button instead of submit stopped the form from submitting, but now how do I submit the form?  Currently I see my temporary alert that tells me what button was pressed.  What should I replace the alert with to submit the form?
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 37703727
(no points...)

Like gd mentioned, change your callback function to submit the form. So replace the temporary alter with something like

var showResult2 = function(btn){
          if (btn == 'yes'){
               // note, I added an "ID" to your cfform
               document.getElementById('yourFormID').submit();
          }
}

<cfform id="yourFormID" name="dg" action="test.cfm">
     ....
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Closing Comment

by:curtis247
ID: 37704239
Thank you, that worked perfectly.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 37704257
curtis247 - I appreciate the points, but in fairness I think it should at least be a split since gd correctly explained why it wasn't working and how to fix it. I just provided a code snippet to illustrate his explanation.  If you're amenable, you can use the request attention and ask a moderator to reopen the question so you can reallocate.
0
 

Author Comment

by:curtis247
ID: 37706036
I agree. Sorry for the mistake.  I will correct as soon as possible.
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 37706079
Thanks to both of you !
0
 
LVL 52

Expert Comment

by:_agx_
ID: 37708257
Thanks curtis!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HTML5 Looping table certain Cell 11 54
Html CheckBox obtain Its Value 5 27
Managing DSNs in CF 11 5 14
Possible propagation problem 1 20
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question