• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

Another submit button issue where page submits when user clicks Cancel

Hi below I have a submit button  and a jquery function it performs when the submit button is clicked on:

<p><input id="submitBtn" name="submitDetails" type="submit" value="Submit Details" onClick="return myClickHandler();" /></p>

Open in new window



         
<script type="text/javascript">
    			
function myClickHandler(){
     if(validation()){
                showConfirm();
                return true;
     }
     return false;
}

</script>

Open in new window


Now as you can see if the validation() function is met, then it will perform the showConfirm() function and this function will perform the confirmation box which is below:

    function showConfirm(){
    
         var confirmMsg=confirm("Make sure that your details are correct, once you proceed after this stage you would not be able to go back and change any details towards Questions, Options and Answers for your Assessment." + "\n" + "\n" + "Are you sure you want to Proceed?" + "\n" );
         
         if (confirmMsg==true)
         {
         submitform(); 
         return true;  
     }else{
     return false;
}
}
            
         function submitform()
{
    var fieldvalue = $("#QandA").val();
    $.post("insertQuestion.php", $("#QandA").serialize() ,function(data){
        var QandAO = document.getElementById("QandA");
        QandAO.submit();
    });  
    alert("Your Details for this Assessment has been submitted"); 
}

Open in new window


MY question is this. If the user clicks on OK in the confirmation box, then it submits the page which is fine. But if the user clicks on Cancel, then it should not submit the page. The problem is that it is submitting the page even though the Cancel button has been clicked on. Why is this?
0
carlbrooks1995
Asked:
carlbrooks1995
  • 2
1 Solution
 
zappafan2k2Commented:
How about trying this:
<script type="text/javascript">
    			
function myClickHandler(){
     if(validation()){
                return showConfirm();
     }
     return false;
}

</script>

Open in new window

In other words, you want to return whatever value showConfirm() returns.
0
 
carlbrooks1995Author Commented:
@zappafan2k2, I have tried your code but still doin same thing
0
 
leakim971PluritechnicianCommented:
three ones :
function myClickHandler()
{
	var v = validation();
	if(v) c = showConfirm();
	return v && c;
}

function showConfirm()
{
	var a = confirm("Make sure that your details are correct, once you proceed after this stage you would not be able to go back and change any details towards Questions, Options and Answers for your Assessment." + "\n" + "\n" + "Are you sure you want to Proceed?\n");
	if(a) submitform();
	return a;
}
            
function submitform()
{
	var fieldvalue = $("#QandA").val();
	$.post("insertQuestion.php", $("#QandA").serialize() ,function(data){
		var QandAO = document.getElementById("QandA");
		QandAO.submit();
	});  
	alert("Your Details for this Assessment has been submitted"); 
}

Open in new window

0
 
leakim971PluritechnicianCommented:
Should do the same job :
function myClickHandler()
{
	if(validation()&&confirm("Make sure that your details are correct, once you proceed after this stage you would not be able to go back and change any details towards Questions, Options and Answers for your Assessment." + "\n" + "\n" + "Are you sure you want to Proceed?\n"));
	{
			var fieldvalue = $("#QandA").val();
			$.post("insertQuestion.php", $("#QandA").serialize() ,function(data){
				var QandAO = document.getElementById("QandA");
				QandAO.submit();
			});  
			alert("Your Details for this Assessment has been submitted"); 
			return true;
	}
	return false;
}

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now