what is the correct way of using the confirm dialog box before the submit form? I see two problem in my implementation, but can´t find solution.  

1)I show a dialog box while submitting. I am using a global variable "val" in ShowConfirmation, this is not visible outside the ShowConfirmation function. If I use debugger, "val" is undefined in ".Submit" function.  

2)Because i have "e.preventDefault" the form is not submitted. Forcing "submit" in function ShowConfirmation does not submit the form.

```
<input type="submit" class="button" value="CONFIRM" onclick="Confirm())">
<Script>
var val;
$("#form").submit(function(e)
{
  // confirmation popup
  e.preventDefault();

  if (val==true)
  {
  // Do something
  }

})

ShowConfirmation(val) {
var r = confirm("Press a button");
if (r == true) {
  console.log("you pressed ok");
  .....
  val=true;
  $("#form").submit();
}
else {
  console.log("you pressed cancel");
  }
}
Confirm() {
...
...
ShowConfirmation(val);
}
</Script>

```