DaVuLf Posted June 1, 2006 Share Posted June 1, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/10965-form-confirmation-cancel-doesnt-cancel/ Share on other sites More sharing options...
lead2gold Posted June 1, 2006 Share Posted June 1, 2006 [!--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] Quote Link to comment https://forums.phpfreaks.com/topic/10965-form-confirmation-cancel-doesnt-cancel/#findComment-40942 Share on other sites More sharing options...
DaVuLf Posted June 1, 2006 Author Share Posted June 1, 2006 That did the trick. What is the difference? Quote Link to comment https://forums.phpfreaks.com/topic/10965-form-confirmation-cancel-doesnt-cancel/#findComment-40944 Share on other sites More sharing options...
wildteen88 Posted June 1, 2006 Share Posted June 1, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/10965-form-confirmation-cancel-doesnt-cancel/#findComment-40953 Share on other sites More sharing options...
DaVuLf Posted June 1, 2006 Author Share Posted June 1, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/10965-form-confirmation-cancel-doesnt-cancel/#findComment-40955 Share on other sites More sharing options...
king arthur Posted June 1, 2006 Share Posted June 1, 2006 [!--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". Quote Link to comment https://forums.phpfreaks.com/topic/10965-form-confirmation-cancel-doesnt-cancel/#findComment-40981 Share on other sites More sharing options...
DaVuLf Posted June 1, 2006 Author Share Posted June 1, 2006 Thanks Arthur, that's exactly what I was looking for. Quote Link to comment https://forums.phpfreaks.com/topic/10965-form-confirmation-cancel-doesnt-cancel/#findComment-41010 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.