Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

submit once help...

Status
Not open for further replies.

thompom

Technical User
Dec 4, 2006
395
GB
Hi,

can someone please show what i need to do to get this to work.

i have an image button on a form that when clicked checks validation then submits the form.
lately people have been clicking more than once so the form is posted twice.

have found a function that prevents this but i cant get it to work with my other onclick events

so far...

submit once function - thanks to javascript.internet.com

Code:
var submitcount=0;

function checkFields() {                     
   if (submitcount == 0)
      {
      submitcount++;
      return true;
      }
   else 
      {
      alert("This form has already been submitted.  Thankyou");
      return false;
      }
   }

my image submit button
Code:
<input name="Action" type="image" id="Action" src="images/tbot6_01.gif" width="87" height="50" border="0" onclick="return EW_checkMyForm(this.form); return checkFields(); return this.form.a.value='A';">

 
Incidentally, if you are going to do this client-side, you should the "onsubmit" event of the form, not the onclick event of any button / image input types for this sort of thing.

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I don't see how you can submit a form twice by clicking on an image 2 times. I think people are refreshing the page after a submit.


The way I handle that is by creating a hidden <input> that contains the current date and time. I also populate a Session variable with the current date and time. If a refresh is done, the <input> will contain the old time where the Session variable will contain a more updated time. Just compare the times, if they are equal process the information from the form, otherwise don't.

This is server-side by the way.



[monkey][snake] <.
 
thanks for your replies

if i use the event on the form what if i have two buttons that do different things?

am going to sort this server side - thanks again

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top