Practically speaking, it'll never happen. It takes about a millisecond
for javascript to do the procedure call, if statement and the
assignment. There's no way anyone could double click that fast unless
there's something else seriously wrong with their machine.

Even if you did get two threads running simultaneously it wouldn't go
into an infinite loop. It would only submit the form twice. There's no
recursion or any function calls in checkSubmit().

I've been using this for years. The only time its ever broken down was
when someone had javascript disabled on their browser.


-----Original Message-----
From: Alan Wolfe [mailto:[EMAIL PROTECTED] 
Sent: April 15, 2004 6:11 PM
To: [EMAIL PROTECTED]
Subject: Re: Witango-Talk: Select a submit button in a form (OT)

oh ok, that makes sense now, thanks (:


----- Original Message ----- 
From: "John McGowan" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, April 15, 2004 2:56 PM
Subject: Re: Witango-Talk: Select a submit button in a form (OT)


> It's a basic race condition...
>
> Like I said it depends on the event handlers being multithreaded...
> Take a look at the code with line numbers...
>
> 1: var submitted=false;
> 2: function checkSubmit()
> 3: {
> 4:  if (submitted==false)
> 5:  {
> 6:    sunmitted=true;
> 7:    return true;
> 8:  }
> 9:  else
> 10:  {
> 11:    alert('Already submitted');
> 12:    return false;
> 13: }
> 14:}
>
> If click 1 spawns thread A and click 2 spawns thread B
>
> If thread A gets to Line 5: and then processing is handed over to
thread
B,
> Thread Be will be able to get to Line 5: as well...
>
> /John
>
> Alan Wolfe wrote:
>
> >could you explain how they could both get caught in the false case?
> >
> >it looks ok to me so just wondering what im missing
> >
> >----- Original Message ----- 
> >From: "John McGowan" <[EMAIL PROTECTED]>
> >To: <[EMAIL PROTECTED]>
> >Sent: Thursday, April 15, 2004 2:43 PM
> >Subject: Re: Witango-Talk: Select a submit button in a form (OT)
> >
> >
> >
> >
> >>Dave Shelley wrote:
> >>
> >>
> >>
> >>>Steve,
> >>>
> >>>On your form tag, add onSubmit="return(checkSubmit())"
> >>>and add a javascript function that says:
> >>>
> >>>var submitted=false;
> >>>function checkSubmit()
> >>>{
> >>> if (submitted==false)
> >>> {
> >>>   sunmitted=true;
> >>>   return true;
> >>> }
> >>> else
> >>> {
> >>>   alert('Already submitted');
> >>>   return false;
> >>> }
> >>>}
> >>>
> >>>That should do it.
> >>>
> >>>
> >>>
> >>>
> >>As long as the Javascript event handlers aren't threaded.  If they
were
> >>threaded, both threads could make it into the "if submitted==false"
branch
> >>
> >>I wouldn't be suprised if the javascript event handlers were
threaded,
> >>because otherwise an infinite loop in one could cause some serious
> >>
> >>
> >problems.
> >
> >
> >>/John
> >>
> >>
> >>
>
>>______________________________________________________________________
__
> >>TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf
> >>
> >>
> >
>
>_______________________________________________________________________
_
> >TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf
> >
> >
> >
>
>
________________________________________________________________________
> TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf

________________________________________________________________________
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf

________________________________________________________________________
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf

Reply via email to