Solved

customized confirmation message box

Posted on 2012-03-09
8
754 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

690 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