472,364 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 software developers and data experts.

How to disbale/enable some links using javascript dynamically?

Hi,

Depending on the user input I need to disbale/enable some of the links
in my page. When disbled I need to display the links as normal text
with cursor changed to mouse pointer style and when enabled I need to
change it back to the normal link.
I tried using document.getElementsById('myLink').style but I am getting
'Object doesnt support this property...'
Can you suggest please ?

Thanks a ton.
CG

Oct 25 '05 #1
2 11805
Lee
cotton_gear said:

Hi,

Depending on the user input I need to disbale/enable some of the links
in my page. When disbled I need to display the links as normal text
with cursor changed to mouse pointer style and when enabled I need to
change it back to the normal link.
I tried using document.getElementsById('myLink').style but I am getting
'Object doesnt support this property...'
Can you suggest please ?


<html>
<head>
<title>enable links</title>
<script type="text/javascript">
function returnTrue() { return true; }
function returnFalse() { return false }
function enableLink(linkid,enable) {
var link=document.getElementById(linkid);
if(enable) {
link.onclick=returnTrue;
link.style.textDecoration="underline";
link.style.cursor="pointer";
} else {
link.onclick=returnFalse;
link.style.textDecoration="none";
link.style.cursor="default";
}
}
</script>
</head>
<body>
<a id="alpha" href="http://www.google.com">google</a><br>
<a id="beta" href="http://www.wikipedia.com">wikipedia</a><br>
<a id="gamma" href="http://www.yahoo.com">yahoo</a><br>
<button onclick="enableLink('beta',false)">disable wiki</button><br>
<button onclick="enableLink('beta',true)">enable wiki</button><br>
</body>
</html>

Oct 25 '05 #2
cotton_gear wrote:
Hi,

Depending on the user input I need to disbale/enable some of the links
in my page. When disbled I need to display the links as normal text
with cursor changed to mouse pointer style and when enabled I need to
change it back to the normal link.
I tried using document.getElementsById('myLink').style but I am getting -----------------------------------^

try:
document.getElementById(...
You only get one of 'em! You might also try using the links
collection rather than getElementById.

'Object doesnt support this property...'
Can you suggest please ?


One option is to have an A element and a span with plain text - hide
the A and show the span for disabled, swap for enabled.
Trivial example:

<a name="appleLink" href="http://www.apple.com">Apple</a><span
style="display: none;" id="appleText">Apple</span><br>

<input type="button" value="disable/enable link" onclick="
var aStyle = document.links.appleLink.style;
var sStyle = document.getElementById('appleText').style;
aStyle.display = ('none' == aStyle.display)? '' : 'none';
sStyle.display = ('none' == sStyle.display)? '' : 'none';
">
--
Rob
Oct 25 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Anshul Gupta | last post by:
Hi, Is there a way i can just print a designated area out of the whole asp(or html) page using javascript or vbscript. i want to mark out the beginning and the end on the page and create a link...
1
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created...
9
by: chrisspencer02 | last post by:
I am looking for a method to extract the links embedded within the Javascript in a web page: an ActiveX component, or example code in C++/Pascal/etc. I am looking for a general solution, not one...
10
by: Trammel | last post by:
Hi, Im just about to start developing a new website for personal / friend use that may be accessed by other people all over the web. I was sitting thinking through designs for the pages, etc when...
1
by: Gerald Shastri | last post by:
Hi, I have a page which is being generated by a CMS and I can't control the links which are being outputted. I want to add a target = "_parent" attribute to all the links on my page using...
1
by: Sirisha | last post by:
Hi, I want javascript for displaying multiple textboxes dynamically. ADD-this is button. if i click button first time it will display 1 textbox and if i click 2nd time it will display another...
2
by: skyy | last post by:
Hi... I want to use ActiveXObject to get some data from the client side. However, some browser does not enable ActiveXObject. Is there any way to enable it using a javascript? Thanks!
1
by: javasachin | last post by:
Hello, I want to enable Struts2 Submit button <s:submit> in the client side using JavaScript based on the user inputs in some other controls (textboxes). If user is not entering any values in the...
1
by: vivek kapile | last post by:
Title:Dynamically adding table row with a checkbox using JavaScript Author:Vivek Kapile Email:snipped Language:JavaScript Platform:JavaScript in ASP.net Technology:Used in ASP.net...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.