Javascript Confirm help

I’m working on a “Document Depo” for pdf storage (using Coldfusion CFFILE tags to upload/move/save …blah. blah…)

If a client tries to load a document into the system that has the same filename of an existing file, I wish to give them the option to overwrite or cancel out.

Coldfusion checks for the existing file, and if it’s there, I do this:

<script type=“text/javascript”>
var OverWrite=confirm(“Another File with This Name Already Exists. Overwrite It?”)
if (!OverWrite)
history.go(-1);
</script>

The problem is - hitting cancel works - it takes them back to the form and they can chose what to do from there.
Hitting “OK” … I need the page to continue to process … but it’s not. It just stops there and doesn’t do anything else.

What am I missing from my javascript above?

Thanks …

You are using a debugging command to try to achieve something - you should use a form in the web page itself to make the selection instead.

The confirm debugging call offers you three options not just two with the third (depending on which browser you are using) either disabling all dialogs for your web page or turning off JavaScript for your page - either of which ensure that no further confirms will appear.

Hi,

In addition to what Stephen said, I just wanted to add that I find the behaviour you describe strange.

When a confirm box pops up, as you know, the user will have to click either “OK” or “Cancel” to proceed.
If the user clicks “OK”, the box returns true. If the user clicks “Cancel”, the box returns false.

In the context of processing a form, if handled correctly, a return value of false should return you to the form, whereas a return value of true should not interfere with the flow of execution.

Here’s a very simple example to demonstrate what I mean:

<!DOCTYPE HTML>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Confirm example</title>
  </head>

  <body>
    <form id="myForm">
      <input type="submit">
    </form>
    
    <script>
      function logNumbersTo(num){
        var conf=confirm("Are you sure about  this?")
        if (conf){
          // Continue processing
          for(var i=0; i<num; i++){
            console.log(i);
          }
        }
      }
      
      f = document.getElementById("myForm");
      f.onsubmit = function(){
        logNumbersTo(10);
        return false;
      }
    </script>
  </body>
</html>

Perhaps I’m missing something.
Could you provide some code or a link to the page in question?