?
Solved

Confirm button still updates changes even after cancel is clicked.

Posted on 2011-04-29
7
Medium Priority
?
355 Views
Last Modified: 2012-05-11
I have a form that has an alert when submitted that says:

Submit? Alert Box with
"OK" or "Cancel"  Button"

"OK"  goes through , submits and alerts "Submitted".

Cancel Alert Box
When clicked says "Not Submitted"  but still submits the edit despite the cancel.

Please help.

Thanks in advance.


<script type="text/javascript">
<!--
function confirmation() {
      var answer = confirm("Submit ?")
      if (answer){
            alert("Updated Succesfully")
            parent.window.location = "index2.asp";
      }
      else{
            alert("Not Submitted!")
            parent.window.location = "index.asp";
      }
}
//-->
</script>
0
Comment
Question by:colonelblue
  • 3
  • 2
  • 2
7 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 35494905
You need to return false; when cancel is clicked
<script type="text/javascript">
<!--
function confirmation() {
      var answer = confirm("Submit ?")
      if (answer){
            alert("Updated Succesfully")
            parent.window.location = "index2.asp";
      }
      else{
            alert("Not Submitted!")
            parent.window.location = "index.asp";
            return false;
      }
}
//-->
</script>

Open in new window

0
 
LVL 19

Expert Comment

by:Greg Alexander
ID: 35494918
Is this what you are looking for?

<script type="text/javascript">
<!--
function confirmation() {
      var answer = confirm("Submit ?")
      if (answer){
            alert("Updated Succesfully")
            parent.window.location = "index2.asp";
      }
      else{
            alert("Not Submitted!")
            parent.window.location = "index.asp";
            return false;
      }
}
//-->
</script>

Open in new window


Are you calling the function from the form like:

<form action="whatever" onsubmit="return confirmation()">

Open in new window

0
 

Author Comment

by:colonelblue
ID: 35495047
Hello guys that still doesn't seem to work.

This is what I have at the bottom of the form:

<script type="text/javascript">
<!--
function confirmation() {
      var answer = confirm("Submit ?")
      if (answer){
            alert("Updated Succesfully")
            parent.window.location = "index2.asp";
      }
      else{
            alert("Not Submitted!")
            parent.window.location = "index.asp";
            return false;
      }
}
//-->
</script>

          <input type="button" class="Cancel_Button" onclick="parent.location='index.asp'" value='Cancel &amp; Close' /></td>
            <td width="25%" align="left"><input  name="Update" type="submit" class="go_button" id="Update" onclick="confirmation()" value="Update" /></td>
          </tr>
        </table>
      &nbsp;
 &nbsp;&nbsp;&nbsp;<br />
      <input type="hidden" name="MM_update" value="form1" />
      <input type="hidden" name="MM_recordId" value="<%= RSRockers.Fields.Item("ID").Value %>" />
      </form>
</td>

Thank you.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 19

Expert Comment

by:Greg Alexander
ID: 35495073
The attached will keep the browser from redirecting, but not sure if that is what you are looking for
<script type="text/javascript">
function confirmation() {
      var answer = confirm("Submit ?")
      if (answer){
            alert("Updated Succesfully")
            parent.window.location = "index2.asp";
      }
      else{
            alert("Not Submitted!")
            return false;
			parent.window.location = "index.asp";
      }
}
</script>

Open in new window

0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 35495145
Good point why are you redirecting on cancel it is this stopping the return false; working
0
 

Author Comment

by:colonelblue
ID: 35495178
I must be doing something wrong.
Regardless of selecting cancel to the Update Alert Box after clicking update, the record is changed.

What I hoped for was to let the user ascertain on whether they want to make the change they had just did before adding it to the database. If they say "cancel", nothing gets updated. If they are certain then it updates. But is seems to update regardless.
0
 
LVL 19

Accepted Solution

by:
Greg Alexander earned 2000 total points
ID: 35495484
Instead of the onclick on the button, you need to build it into the form function... here is an example of what I mean:
<script type="text/javascript">
<!--
function confirmation() {
	
	  if(!confirm("Submit ?")){
		  return false;
	  }
	  
}
//-->
</script>

<form action="whereever" name="whatever" onsubmit="return confirmation()">

<input type="submit" name="submit" value="Submit" />

</form>

Open in new window


Does that make any sense? I realize its not what you are looking for, but I think we could build on this concept
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Suggested Courses

850 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