How can i disable a link after its clicked?
Showing comments 1 to 4 of total 4 on page 1 of 1
sreejithRank: 128
I have this link that publishes a form.
link('Publish',"/forms/publish/".$r['Form']['id']."/".$userid);?>
Once a form is published,this link should be disabled. I tried using css style to make the publish link disappear,something like
a.disappear:visited{
display:none;
}
Publish
But im not satisfied with the results. Does anyone here have a better idea?
starblueRank: 131
You can empty the href/onclick attribute after click, by setting a short timeout on a function (in the onclick attribute). You cannot empty the href right away because it's called before the link action is performed.
Else instead of display: none; you can try visibility: hidden; which will hide the link but keep the space and not mess up your layout. But then you should know that using the :visisted CSS selector has its drawbacks and traps (not in history anymore because cleaned or too old, published by someone else, css disabled, want to unpublish then re-publish...).
balajiRank: 74
Something like this??
<style>
.textdecnone
{
text-decoration : none;
}
</style>
<script>
function disableThis(id)
{
document.getElementById(id).className = "textdecnone";
document.getElementById(id).onClick="";
document.getElementById(id).removeAttribute("href");
}
</script>
<center>
<table border = "0" cellspacing="0" cellpadding="0">
<tr>
<td>
<a id="myLink" href="javascript:void(0);" onclick="disableThis('myLink');">Click Here
</a>
</td>
</tr>
</table>
</center>
rajkumar...Rank: 4
The simplest one :
<a href="link.html" onclick="this.href='javascript:void(0)';this.disabled=1">click here</a>
<a href="foo.php" onclick="this.onclick=function(){return false;}">
A little tricky one
A old fashioned typeif (document.MM_returnValue) {
document.getElementById('submitButton').disabled = true;
}
...
<input name="submit" id="submitButton" tabindex="17" type="image" src="images/submit.jpg" value=Submit>
<html>
<head>
<script type="text/javascript">
function disableOtherLinks(URL){
globalHtml="<html><body>Please Wait<script type=\"text/javascript\">"
+"location=\""+URL+"\";<\/script></body></html>";
location="javascript:window.globalHtml";
}
</script>
</head>
<body>
<a href="http://www.google.com"
onclick="disableOtherLinks('http://www.google.com');return false">Google</a>
<a href="http://www.yahoo.com"
onclick="disableOtherLinks('http://www.yahoo.com');return false">Yahoo</a>
</body>
</html>