Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Dynamically Find My Link Number

Status
Not open for further replies.

soho34

IS-IT--Management
Dec 28, 2004
102
US
Hi,

I have a link defined as follows:

<a href="" id="clrest">Restrict</a>

Now, in my JS function, I'm disabling/enabling the link as follows:

document.links[2].disabled = true;

However, I need to change my JS statement from referencing "2" to referencing whatever position that link happens to be, so I modified my code to this:

function disableLink(){

var rnum = document.getElementById("clrest").value;
document.links[rnum].disabled = true;

}

But for rnum, I keep getting "undefined". What is my problem? I thought using the getElementByID and the value attribute would return the position of that particular link.

Am I doing something wrong?

Thanks in advance for your help.

soho34
 
Hi BabyJeffy,

Thanks so much for your reply. However, I'm still getting an "Object Expected" Error. Here's what I currently have:

Code:
function DisableEnableLinks(){ 

		//grab the link number of the Restrict link
		var rnum = document.getElementById("clrestrict").innerHTML;
		alert("rnum = " + rnum); [COLOR=red]....this gives me the name, not number of link[/color]
	        
        document.links[rnum].disabled = false; 
		[COLOR=red]....when I get ready to use it, its not a number [/color]

}

Any additional advice? Thanks for your help.

soho34
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top