Jump to content

Form Confirmation - Cancel Doesn't Cancel.


DaVuLf

Recommended Posts

I have a form on my page.

[code]
<form action="insert.php" method="post">
[/code]

I have a submit button on the page.
[code]
<input name="Submit" onclick="confirmation()" type="Submit" />
[/code]

I have a confirmation function.
[code]
<script type="text/javascript">
<!--
function confirmation() {
    var answer = confirm("Is this transaction information correct?")
        if (answer){
            return true;
        }else{
            return false;
        }
}
//-->
</script>
[/code]

Now I'm wondering why when I click submit, and it asks for confirmation, and I click cancel, it still submits the form. Shouldn't it just let me fill in more data? Or correct what was incorrect. The whole point of confirmation seems to suggest that if the data is incorrect, that we have the opportunity to modify it before submission. Unfortunately, it seems to me like that isn't happening in this instance.

Any help would be appreciated.

Thanks,
DaVuLf
Link to comment
Share on other sites

[!--quoteo(post=379094:date=Jun 1 2006, 11:14 AM:name=DaVuLf)--][div class=\'quotetop\']QUOTE(DaVuLf @ Jun 1 2006, 11:14 AM) [snapback]379094[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I have a form on my page.

[code]
<form action="insert.php" method="post">
[/code]

I have a submit button on the page.
[code]
<input name="Submit" onclick="confirmation()" type="Submit" />
[/code]

I have a confirmation function.
[code]
<script type="text/javascript">
<!--
function confirmation() {
    var answer = confirm("Is this transaction information correct?")
        if (answer){
            return true;
        }else{
            return false;
        }
}
//-->
</script>
[/code]
[/quote]

i think you need to do this:

[code]
  <input name="Submit" onclick="return confirmation();" type="Submit" />
[/code]
Link to comment
Share on other sites

I noticed what he had added, which changed the way it worked, but I was wondeirng why. In reality, the form itself was still submitting, and the actions were being processed. The issue was that the cancel portion was not working.

Regardless, it is working now, and for that I must thank Lead.
Link to comment
Share on other sites

[!--quoteo(post=379112:date=Jun 1 2006, 05:27 PM:name=DaVuLf)--][div class=\'quotetop\']QUOTE(DaVuLf @ Jun 1 2006, 05:27 PM) [snapback]379112[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I noticed what he had added, which changed the way it worked, but I was wondeirng why. [/quote]

Because the onclick event must return the value 'false' in order to cancel the submission. Without explicitly returning the value from your confirmation function, it just gets lost and the default value is returned from the event, which is "true".
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.