Link to home
Start Free TrialLog in
Avatar of colonelblue
colonelblue

asked on

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>
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

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

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

Avatar of colonelblue
colonelblue

ASKER

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.
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

Good point why are you redirecting on cancel it is this stopping the return false; working
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.
ASKER CERTIFIED SOLUTION
Avatar of Greg Alexander
Greg Alexander
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial