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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting and disabling when a link has been clicked more than once

Status
Not open for further replies.

programmher

Programmer
May 25, 2000
235
0
0
US
I have a link on a page that opens another page. My problem arises when the user accidentally clicks the link more than once. The information from the child form does not pass to the parent form when the link is clicked twice.

Below is the code:

<script>
onload=function(){
var lnks=document.links
for (var ii=0; ii<lnks.length; ii++){
var current=lnks[ii];
current.onclick=function(){ alert(this.href+&quot; clicked&quot;);}
return false;
}
}
</script>

Can anyone advise a way to disable clicking the link more than once?
 
<script language=&quot;javascript&quot;>
var clicked = false;

function doClick() {
if (!clicked) {
alert(&quot;Clicked!&quot;);
}
clicked = true;
return !clicked;
}
</script>

<a href=&quot;#&quot; onclick=&quot;doClick();&quot;>click me</a> =========================================================
if (!succeed) try();
-jeff
 
Jeff,

Thanks for the script. I got the message; but the page still reloaded. I tried using return false; but it still loaded.

<script language=&quot;javascript&quot;>
var clicked = false;

function doClick() {
if (!clicked) {
alert(&quot;Clicked!&quot;);
return false;
}
clicked = true;
return !clicked;
}
</script>

What else can I use to keep the form from re-loading?
 
are you trying to prevent a form from being submitted?

<script language=&quot;javascript&quot;>
var clicked = false;

function doClick() {
if (!clicked) {
alert(&quot;Clicked!&quot;);
return false;
}
clicked = true;
return false;
}
</script>


<form onsubmit=&quot;return doClick();&quot;>

=========================================================
if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top