Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 27th, 2009, 07:35 AM
Friend of Wrox
 
Join Date: Dec 2006
Posts: 104
Thanks: 9
Thanked 1 Time in 1 Post
Default Prevent Double click on href link


Chaps,

Been having a search for a solid JavaScript solution to a double click href issue i am experiencing.

Using some examples i have found, i have written the following process .. Issue being it works in IE but not Firefox.

Below are the hrefs:

Code:
<a href="#" onClick="TrueUrl();">
<img src="true.gif" alt="True" border="0"></a>


Code:
<a href="#" onClick="FalseUrl();">
 <img src="false.gif" alt="True" border="0"></a>


Below is the Javascript:

Code:
<script language="javascript" type="text/javascript">
var flag = 1
//Send True querystring
function TrueUrl()
{
if(flag) // if it's okay to proceed
{
flag = 0
window.navigate("tfsubmit.asp?val=t")
flag = 1
}
else
{
// do nothing.. except maybe yell at the over-anxious user
}
}
</script>
<script language="javascript" type="text/javascript">
var flag = 1
//Send False querystring
function FalseUrl()
{
if(flag) // if it's okay to proceed
{
flag = 0
window.navigate("tfsubmit.asp?val=f")
flag = 1
}
else
{
// do nothing.. except maybe yell at the over-anxious user
}
}
</script>


My knowledge of JavaScript is even worse than my asp so if anyone can point me in the right direction that would be great.


Cheers

Aspless
 
Old May 27th, 2009, 07:46 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 207
Thanks: 2
Thanked 15 Times in 15 Posts
Default Maybe I don't get it...

...But can't you just do that all in one function?

Code:
<script language="javascript" type="text/javascript">

var flag = 't';

function TrueUrl()
  {
    window.navigate('tfsubmit.asp?val=' + flag);
    if(flag == 't')
      {
        flag = 'f';
      }
   else
     {
       flag = 't';
     }
  }
</script>
<a href="#" onClick="TrueUrl();"><img src="true.gif" alt="True" border="0"></a>


There is probably and even better way to do this but if I understand correctly I think that might do what you want?
__________________
Jason Hall

Follow me on Twitter @jhall2013

Last edited by alliancejhall; May 27th, 2009 at 07:53 PM..
 
Old May 28th, 2009, 12:09 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

No, no, Jason...the val= in the URL has *NOTHING* to do with the state of the flag. It matches the ".gif" image the user clicks on.

Aspless: The issue *MIGHT* be that you are using the numbers 1 and 0 for your flag but then treating them as true/false. Be consistent. And Jason is right, you could do this all with a single function, though not the way he coded it:
Code:
<script>
var already = false;
function gothere(which)
{
    if ( already )
    {
        alert("Please wait...we are already processing your request...");
        return false;
    }
    already = true;
    location.href = "tfsubmit.asp?val=" + which;
    return false;
}
</script>

<a href="#" onClick="return gothere('t');"><img src="true.gif" alt="True" border="0"></a><a href="#" onClick="return gothere('f');"><img src="false.gif" alt="False" border="0"></a>
Don't forget the return false! And don't forget the return in the onClick. Otherwise, the browser is entitled to refresh the page, going to the top of the page (that's what href="#" means).
 
Old May 28th, 2009, 12:11 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

I think I see why it failed: You are changing the state of the flag *after* the call to window.navigate, and the browser *could* be simply ending all processing in the function as soon as it does the window.navigate.

Note that I changed the flag *before* changing the URL. I doubt that it matters whether you use window.navigate or location.href.
The Following User Says Thank You to Old Pedant For This Useful Post:
aspless (June 12th, 2009)
 
Old June 12th, 2009, 02:08 PM
Friend of Wrox
 
Join Date: Dec 2006
Posts: 104
Thanks: 9
Thanked 1 Time in 1 Post
Default

Thanks .. Now working really well





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to prevent page jumping while click on iframe' kathirnk HTML Code Clinic 0 April 16th, 2007 06:39 AM
double click to open link thutt Dreamweaver (all versions) 0 February 8th, 2007 05:01 PM
XML value in HRef link aware XSLT 3 January 8th, 2007 08:52 AM
Right-Click or Double-Click Combobox? panuvin C# 2005 3 June 15th, 2006 04:30 PM
Double Click problem Merlin Java GUI 1 March 31st, 2004 10:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.