Click here to Skip to main content
15,851,387 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on an project where I need to be able to disable several hyperlink controls on the fly in javascript when the user starts a transaction. I don’t want them to be clicking links in the middle of it – accidental or not.

I have researched and tried several things that have not worked. This involved setting the “enabled” property to false, “disabled” properlty to true and settign the .href property to “#”. None of these worked.

I then discovered that even trying to access the hyperlink field using “document.getelementbyid” was unsuccessful, so this could be a HUGE part of the issue…

I tried using the following… (also tried using the clientid and still no go)

var myHL = document.getElementById("MainContent_hl_first"); (doesn’t seem to work)
myHL.enabled = false (doesn’t work because above assignment doesn’t work)

also tried…
document.getElementById("MainContent_hl_first").enabled=false; (doesn’t work)

also tried
document.getElementById("MainContent_hl_first").disabled = false; (doesn’t work)

As a test, I hard coded an “onclick” event into the html code that sets up the element and it works… So how can I add this on the fly in javascript, keeping in mind that accessing the control using the document.getelementbyid doesn’t seem to work? (because otherwise I could have just set the .onclick event…)

onclick="return false"

(unfortunately on this site because of the formatting when I pasted my html code for the above, it totally changed it around and left a bunch of stuff out and replaced other stuff - so it's useless to paste anything in with html tags in it...)
Richard Deeming 15-May-15 15:23pm    
If document.getElementById isn't returning the element, then you don't have an element in your document with that ID. Look at the source of the page and find the correct ID.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900