Mike Mike - 1 year ago 129
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");

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");

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 Source

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

function check(link) {
if (link.className != "visited") {
   link.className = "visited";
   return true;    
return false;


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download