[OCLUG-devel] JavaScript - An enhanced confirmation dialog box

Doug Jolley ddjolley at gmail.com
Thu Jul 21 09:08:24 PDT 2005


Basically what I'm trying to produce is a confirm dialog box on
sterroids.  After a user has finished entering data into a form and
clicks the submit button, I want to do some error checking on the data
and if it's OK open a window which will present a summary of the data
submitted and ask the user via Accept and Cancel buttons whether he
wants to submit the data.

I am appending my code below.

I intended that if the user clicks the Accept button the verify()
function would return true and the form data would be submitted.  If
the user clicks the 'Cancel' button, the verify function returns false
and the form data would not be submitted leaving the user in the
position of being able to edit the form data before submitting it.

What seems to be happening is that the verify() function is returning
true right away (i.e., before the user has done anything).  So, even
though the window is open presenting the user with the 'Accept' and
'Cancel' buttons, the form data is immediately submitted without
regard for what button the user ultimately clicks.  Can anyone think
of how I might resolve this delima?  Thanks.  Here's my code.

<html>
 <head>
   <title>Test 3</title>
<script language="JavaScript">
<!--
function verify() {
// Some error checking code goes here.
confirmWin=open("","confirmWindow","toolbar=1")
confirmWin.focus()
confirmWin.document.open()
confirmWin.document.write("My dog has fleas.")
confirmWin.document.write("<p><input type=\"button\" name=\"accept\"
value=\"Accept\" onclick=\"return true\"></p>")
confirmWin.document.write("<p><input type=\"button\" name=\"cancel\"
value=\"Cancel\" onclick=\"return true\"></p>")
confirmWin.document.close()
}
// -->
</script>
</head>
 <body>
  <form action="/dev/null" name="roForm" method="post"
onsubmit="return verify()">
   <input type="submit">
  </form>
 </body>
</html>


More information about the OCLUG-devel mailing list