File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Disable a link a href Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Disable a link a href" Watch "Disable a link a href" New topic

Disable a link a href

Gayatri Sinha
Ranch Hand

Joined: Feb 13, 2006
Posts: 34

I am trying to disable the link
<a href="" disabled="true">Click here</a>

But when I click on "Click here" the link works, looks like only the text is greyed.
How do I disable the link?

I have this in a jsp page which has a boolean bit
So I want to do something like

<a href="" disabled="<%= bit>">Click here</a>

Is this possible?

Christian Gross
Ranch Hand

Joined: Feb 20, 2006
Posts: 85
Try the following

<a href="/whatever" onclick="return false" />


Author of Ajax Patterns and Best Practices
Kj Reddy
Ranch Hand

Joined: Sep 20, 2003
Posts: 1704
If you disable hyper link its just becomes normal text right? If you want to open a page on some condition write a java script function and call it from href. If the condition satisfied you open page otherwise just do nothing.

code looks like this:

<a href="javascript: openPage()" disabled="<%= bit>">Click here</a>

and function:
function openPage()
if(some conditon)
opener.document.location = "";
// nothing, this else not required

hope it is helpful to you
[ February 24, 2006: Message edited by: KJ Reddy ]
Gayatri Sinha
Ranch Hand

Joined: Feb 13, 2006
Posts: 34
great thanks a lot
I agree. Here's the link:
subject: Disable a link a href
It's not a secret anymore!