Jump to content
  • Advertisement
Sign in to follow this  
ballack

[web] disabling a hyperlink

This topic is 4397 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi everyone, i want to know how can i disable a hyperlink in html using javascript. for example i ve a checkbox when a user unchecks the check box the link should be disabled. can anyone help me with this? -Glen

Share this post


Link to post
Share on other sites
Advertisement
You could swap out two entire divs/spans based on that event. The 'normal' one would include a hyperlink, and the post-click one would be standard text.

Share this post


Link to post
Share on other sites
You can do this by using the 'onclick' handler on the link - return false to disable the link, true to enable it.
As an example, the following link only works the 3rd time you click on it:


<a href="http://www.example.com" onclick="return condition();">Link</a>

<script language="JavaScript">
var count = 1;
function condition() {
return (count++ == 3);
}
</script>

Share this post


Link to post
Share on other sites
Something like this?


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<title>TEST</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">

function updateLink(srcCheckbox, linkId)
{
var theLink = document.getElementById(linkId);

if (theLink)
{
if (srcCheckbox.checked)
theLink.style.visibility = 'visible';
else
theLink.style.visibility = 'hidden';
}
};

</script>

</head>
<body>

<input type="checkbox" name="myCheckbox" onclick="updateLink(this, 'myLink');" checked /> Click me!

<p>
<a id="myLink" href="http://www.gamedev.net" target="_blank">Go to GameDev.net</a>
</p>

</body>
</html>

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!