How can i disable a link after its clicked?

Posted in Help the coder! on Jul 9, 2009 at 22:10 IST (about 1 year ago). Subscribe to this post Bookmark and Share Email
Showing comments 1 to 4 of total 4 on page 1 of 1
Tagged cakephp, link, php
Post reply
« Previous1Next »

sreejith
Rank: 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?

Posted by sreejith on Thursday, July 9, 2009, 10:10 pm
  • Currently 0.00/5

0 votes

Thank this userFlag this comment

starblue
Rank: 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...).

Posted by starblue on Thursday, July 9, 2009, 10:56 pm
  • Currently 0.00/5

0 votes

Thank this userFlag this comment

balaji
Rank: 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>

Posted by balaji on Friday, October 9, 2009, 12:57 am
  • Currently 0.00/5

0 votes

Thank this userFlag this comment

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
if (document.MM_returnValue) {
document.getElementById('submitButton').disabled = true;
}
...

<input name="submit" id="submitButton" tabindex="17" type="image" src="images/submit.jpg" value=Submit>
A old fashioned type

<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>
Thankful users: xtrmprgrmr
Posted by rajkumar_pb on Friday, October 9, 2009, 2:54 am
  • Currently 0.00/5

0 votes

Thank this userFlag this comment
Pages: « Previous1Next »

Post your comment (No registration required)

  Add my comment  

TechieDesi Community

Not signed in (Sign-in or Register)
Be a true TechieDesi!
Top 10 Users
Spread the word
Invite your friends
Fan stuff
Help us improve
Need Help
FAQ's
Search tips
Found a bug? Report!
Feeds and letters
Subscribe via RSS
Archives
Subscribe to newsletter
Unsubscribe e-mail
Miscellaneous
Privacy policy
Visit rootnerve
About us
About us
Support the development
Official Blog
Advertise with us
Careers
Copyright (c) 2008, TechieDesi.com. All rights reserved | About us | Do-Not-Disturb registry | Powered by rootnerve | Page rendered in 0.108 seconds