Mike Mike - 5 months ago 26
HTML Question

How to disable href after one click

I wish to disable a href after clicking it once.

I have the following href:

<a href="BeginPayment.aspx?PayPal=true" id ="link" onclick="javascript:clickAndDisable();">


I have added the onclick event that gets called on click.
I have attempted to change the href to be a blank path so that it cannot be clicked a second time: This is via a Javascript function.

function clickAndDisable(link)
{
alert("Entered clickAndDisable function");
this.href="''";
}


My code is all within an xslt file.
Where am i going wrong with this?

Here is my updated code following peoples suggestions:

<a href="BeginPayment.aspx?PayPal=true" id ="link" onclick="javascript:clickAndDisable(this);">

<script type="text/javascript">

function clickAndDisable(link)
{
alert("Entered clickAndDisable function");
link.href="";
}




This disables the link from working at all, I wish for the link to work the first time it is clicked, but not work any other time it is clicked.....

Answer

I ended up disabling the href after one click using the following javascript function:

function check(link) {
if (link.className != "visited") {
   //alert("new");
   link.className = "visited";
   return true;    
}
//alert("old");
return false;

}​​

Comments