Skip to main content
Known Participant
May 9, 2006
Question

disable/enable

  • May 9, 2006
  • 3 replies
  • 609 views
I know it could be a wrong forum for me to post this question but I think a lot of expert people here can help me with this. I found this from the website and I try to modify it to make it work for my case but I am not able too.

There is an original function called “toggleLink” to make the link disabled or enabled the link. It worked, however, both disable and enable are work within the same button which is I don’t want.

I modify it into two functions: disable and enable but I can’t make it work.
Thanks
========
This topic has been closed for replies.

3 replies

May 10, 2006
Sure... you could reference each link by adding an "id". (see below)

<script language="javascript">
function en(str) {
var obj = document.getElementById(str)
obj.disabled = false;
obj.onclick = new Function("return true;");
}
function dis(str) {
var obj = document.getElementById(str);
obj.disabled = true;
obj.onclick = new Function("return false;");
}
</script>

<div>
<input type="button" value="enable 1" onclick="en('link1')" />
<input type="button" value="disable 1" onclick="dis('link1')" />
</div>

<div>
<input type="button" value="enable 2" onclick="en('link2')" />
<input type="button" value="disable 2" onclick="dis('link2')" />
</div>

<a href="ip.cfm" id="link1">This is my link1</a>
<a href="ip.cfm" id="link2">This is my link2</a>
Participating Frequently
May 10, 2006
You're gonna need to pass something in to identify which link.

<script language="javascript">
function en(linkId) {
var link = document.getElementById(linkId);
link.disabled = false;
link.onclick = new Function("return true;");
}
function dis(linkId) {
var link = document.getElementById(linkId);
link.disabled = true;
link.onclick = new Function("return false;");
}
</script>

<input type="button" value="enable" onclick="en('link1')" />
<input type="button" value="disable" onclick="dis('link1')" />

<a href="ip.cfm" id="link1">This is my link</a>
May 9, 2006
Is this what you were looking to do?

<script language="javascript">
function en() {
document.links[0].disabled = false;
document.links[0].onclick = new Function("return true;");
}
function dis() {
document.links[0].disabled = true;
document.links[0].onclick = new Function("return false;");
}
</script>

<input type="button" value="enable" onclick="en()" />
<input type="button" value="disable" onclick="dis()" />

<a href="ip.cfm">This is my link</a>
newcfAuthor
Known Participant
May 10, 2006
cfpb ,

Thanks for your responsed. Yes, this is what I want, however, there are more than one links on the page and this one was not the first link, therfore, it doesn't know what link they need to dis or en. Is there any way to tell specific what link i need to dis or en?

Thanks again.