Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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
Author

Disable a link a href

Gayatri Sinha
Ranch Hand

Joined: Feb 13, 2006
Posts: 34
HI,

I am trying to disable the link
<a href="http://www.google.com" 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="http://www.google.com" disabled="<%= bit>">Click here</a>

Is this possible?

Thanks
Christian Gross
Author
Ranch Hand

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

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


Christian


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 = "http://www.google.com";
}
else{
// 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
 
Don't get me started about those stupid light bulbs.
 
subject: Disable a link a href