[thelist] Seeking JS Solution for Double Form Submission????

Keith cache at dowebs.com
Mon Jul 16 16:22:34 CDT 2001


 How can I disable the
> submit buttons are the first submission?

I disable submit buttons with the following. It disables the button only 
if the visitor has javascript enabled, which covers the majority of 
users.  The noscript tag is not available to NN2 and some early 
releases of IE3.  For that reason I use this on a dynamic or SSI 
page that has determined their user-agent (sending a degraded 
page if NN2 or IE3). In the body put:

<script language=javascript>
sent=0
function send(Form){
Form.sender.value="Wait"
if(sent==0){Form.submit()}
sent=1
}
document.write('<input type=button name=sender value="Submit" 
onclick="send(this.form)">')
</script>
<noscript>
<input type=submit name=sendit value="Submit"><br>
Click this more than once if you want weird stuff to happen
</noscript>

Those without js enabled can get past this, The script just 
decreases your problem. Look at the different names used for the 
two buttons. If "sendit" gets sent to the server the visitor had js 
turned off so you need to track their clickity clicks on the server. If 
putting a warning on the page is not sufficient you'll need to track 
them as you are, with some form of session key, either in a cookie 
or, if it is unreasonable to require cookies, in a file that you'll need 
to cleanup later. 

One positive way to do cleanup is to include a one pixel image on 
the return page <img src=cleanup.cgi?key width=1 height=1> . The 
cleanup.cgi looks for the key and deletes the entry, opens a 
transparent gif and returns it with an image/gif mime. 

If you first filter the submissions with the javascript you will need to 
track the submission and perform cleanup only on submissions 
receiving the javascript disabled "sendit" name.

keith





More information about the thelist mailing list