Jump to content

Archived

This topic is now archived and is closed to further replies.

DaVuLf

Form Confirmation - Cancel Doesn't Cancel.

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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
the added keyword [b]return[/b] before you call the confirmation function with in the onclick attribute on you input tag, Without that your form won't submit.

Share this post


Link to post
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.

Share this post


Link to post
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".

Share this post


Link to post
Share on other sites

×

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.