473,549 Members | 2,329 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getEle mentsById('myLi nk').style but I am getting
'Object doesnt support this property...'
Can you suggest please ?

Thanks a ton.
CG

Oct 25 '05 #1
2 11890
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.getEle mentsById('myLi nk').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(link id,enable) {
var link=document.g etElementById(l inkid);
if(enable) {
link.onclick=re turnTrue;
link.style.text Decoration="und erline";
link.style.curs or="pointer";
} else {
link.onclick=re turnFalse;
link.style.text Decoration="non e";
link.style.curs or="default";
}
}
</script>
</head>
<body>
<a id="alpha" href="http://www.google.com" >google</a><br>
<a id="beta" href="http://www.wikipedia.c om">wikipedia </a><br>
<a id="gamma" href="http://www.yahoo.com"> yahoo</a><br>
<button onclick="enable Link('beta',fal se)">disable wiki</button><br>
<button onclick="enable Link('beta',tru e)">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.getEle mentsById('myLi nk').style but I am getting -----------------------------------^

try:
document.getEle mentById(...
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.getEle mentById('apple Text').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
14446
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 just to print out that section. Please help me if there is any way to do this. Thankyou
1
3114
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 elements and would like to seek a solution for this. I had looked through several articles for accessing programatically-created dynamic elements such...
9
3488
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 tailored to a particular page/script. Hopefully, the problem can be solved without recreating a complete Javascript interpreter. Any ideas?
10
2195
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 I came across a thought.... ....why show the visitor loads of junk just because Im using A-href type links? Is there a way to create a...
1
6027
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 javascript. Can anyone tell me how to do it. Thanks a lot. Gerald.
1
8401
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 textbox,if i click that button once again display another textbox.if i click 10 times it will display 10 textboxes. so i want code for displaying...
2
4220
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
3875
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 text boxes, I want to disable the <s:submit> and if user enters any text, then I want to enable this <s;submit. button. Can you kindly tell me how to...
1
34098
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 Level:Beginner Introduction
0
7546
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7985
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6071
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5387
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3517
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3496
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1082
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.