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

Confirm button still updates changes even after cancel is clicked.

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
colonelblue
Asked:
colonelblue
  • 3
  • 2
  • 2
1 Solution
 
Paul JacksonSoftware EngineerCommented:
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
 
Greg AlexanderLead DeveloperCommented:
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
 
colonelblueAuthor Commented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Greg AlexanderLead DeveloperCommented:
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
 
Paul JacksonSoftware EngineerCommented:
Good point why are you redirecting on cancel it is this stopping the return false; working
0
 
colonelblueAuthor Commented:
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
 
Greg AlexanderLead DeveloperCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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