codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Preventing form submission twice on doubleclick in NN6.  G4Gun at 07:15 on Monday, February 16, 2004
 

Hi,
I have a form in which I have this link :- <a href="javascript:submitform(parameters );"> . In the JavaScript
function submitform, there is the code for submitting the form.This works fine with single click on both IE,NN6.In IE the form is submitted only once even for double click.But if you double click on the link in NN6,the form is submitted twice. This causes problem. The workaround for this was that we set a flag(indicating form submission) in the submitform function, we also set a timer which calls the function resetflag after 3 seconds.So any click within 3 seconds of the first click will be ignored (so that the form is not submitted for the second click).

function submitform(params)
{
if(flag==0)
{
flag=1;
timeout = setTimeout('resetflag()',3000);
document.form1.action = someURL;
document.form1.submit();
}
}

function resetflag()
{
flag=0;
}
.
.
.
.
.
.
.
//Javascript variables initialization.Executed while page loading.
var flag=0;
var timeout=0;

But the problem now is that, the event fired on the first click submits the form to the server.The second click
is ignored since the flag is 0.But the results to be showed for the first click event fired are not shown.The
page just stands still as if no event was fired.I dont want to show any alerts or message like 'Double click is not allowed'. I just want a situation where double click has the same effect as single clicki.e. form should be submitted only once(as in single click) and the results should be displayed. Can Anyone Help?

  Re: Preventing form submission twice on doubleclick in NN6.  dma at 15:11 on Tuesday, March 16, 2004
 

Hi,

I am encountering exactly the same problem.
Did you find any solution to this problem yet?
I will let you know if I find something.

David.

  Re: Preventing form submission twice on doubleclick in NN6.  Troy Wolf at 19:25 on Tuesday, March 16, 2004
 

Hmmmm... You know how you can click a link in the browser, and if you click a second link BEFORE the first link navigates, you will in essence cancel the first click and instead navigate to the second clicked link?

Is this what is happening in your case? The first click fires and sets your flag that prevents the form from re-submitting a second time. Then the second click fires which cancels the navigation of the first click, but the second click doesn't actually do anything since your flag tells it not to submit?

What I'm wondering is, does the first click actually submit the form, but then fails to navigate to the results? You'll need to have your page that you submit to do something on the server that will allow you to see if it really was submitted -- like update a table or create a file. Then do your test. You'll double click, the first click will submit, the second will appear to do nothing, and your page content will not refresh. Now go check your server--did the form actually submit and process?

Try this, add "target=_blank" to your form tag.
<form target=_blank name=MyForm method=POST action=MyPage.html>

Now, your first click should submit the form to the new window. The second click will intervene in the first window, but that should not affect the new window from completing it's task and showing the results. I'm not suggesting this is your final solution, but it will help us understand WHAT exactly is happening.

Do some experimenting and let us know!

Troy Wolf: site expert
SnippetEdit Website Editor


  Re: Preventing form submission twice on doubleclick in NN6.  dma at 12:23 on Wednesday, March 17, 2004
 

Hi,

>What I'm wondering is, does the first click actually >submit the form, but then fails to navigate to the >results?

I set up a little test and this is indeed what is happening. The first click submits the form, but then
the second click cancels the first click. Since the second click does not submit the form anymore, nothing happens.

I found a workaround on some other site : if the link is disabled just before submitting the form, double-clicking becomes impossible.

function disable_buttons()
{
if (document.all || document.getElementById)
{
for (i=0; i<document.form1.length ; i++)
{
if (document.form1.elements.type.toLowerCase() == "submit" ||
document.form1.elements.type.toLowerCase() == "button" )
{
document.form1.elements.disabled = true;
}
}
}
}

function cancelLink ()
{
return false;
}

function disable_links()
{
if ( document.links )
{
for (i=0; i<document.links.length ; i++)
{
document.links.onclick = cancelLink;
if (document.links.style)
{
document.links.style.cursor = 'default';
}
}
}
}

function submitForm()
{
disable_buttons();
disable_links();
document.form1.submit();
}

Regards,



  Re: Preventing form submission twice on doubleclick in NN6.  Troy Wolf at 13:57 on Wednesday, March 17, 2004
 

Glad you got a working solution. I'm still curios, did your tests confirm that indeed the first click DID submit the form to the server--and that form was processed?

If so, then the only problem was the second click cancelled the local browser's navigation--but the form was submitted fine. This is why simply having a script to disable all links and buttons just before submitting solves the problem.

Good work!
Troy Wolf: site expert
SnippetEdit Website Editor


  Re: Preventing form submission twice on doubleclick in NN6.  dma at 18:46 on Sunday, March 21, 2004
 

Hi,

> Glad you got a working solution. I'm still curios, did > your tests confirm that indeed the first click DID
> submit the form to the server--and that form was
> processed?

Yes, when the page is processed our application makes a call to another server to query a database (which is why it takes so long to show any result) . I clearly saw the request to the other server appearing in the logs, which means the page was submitted and processed after the first click. Normally after the query to the remote database another page should appear in the browser, but the second click was cancelling that action.

Best regards,

David








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Develop website with 3 tier architecture
•  Re: TaylorMade R11s Fairway Wood
•  Re:
•  What do you mean by ASP.NET MVC Execution Process?
•  Re:
•  Re:
•  one java progarm handle two socket connection
•  How to navigate database page?
•  "Fitting Wedges


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2012