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

Chris Berry chris_berry-list-oclug-devel at jm-associates.com
Thu Jul 21 12:28:55 PDT 2005


I'm pretty sure this forum is for all programming not just C, so 
JavaScript is definitely ok here, though I suppose you'd probably get 
some flack if you wanted to talk VBScript or windows batch files hehe.

My JavaScript is a litte rusty, but I think this is your problem:

<form action="/dev/null" name="roForm" method="post"
onsubmit="return verify()">

You don't return directly in the onSubmit event handler, you return from 
the function. So onSubmit should be onsubmit="function()", and the 
function should return true or false.  The way you've got it set, it's 
always true even before the function runs.

Chris Berry
chris_berry at jm-associates.com
Information Advisory Manager
JM Associates

"There is nothing so useless as doing efficiently that which should not 
be done at all." --Peter Drucker

Doug Jolley wrote:
> 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>
> _______________________________________________
> OCLUG-devel mailing list -- OCLUG-devel at oclug.org
> http://mailman.oclug.org/mailman/listinfo/oclug-devel


More information about the OCLUG-devel mailing list