• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question on "a href "

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm fairly new to HTML & scripting.
I need to disable a " a href link" on a particular condition.
I tried using "disabled" property.It just grays out the link and the link can still be clicked.
I want to make it non-clickable.Is there a way to do this?
Please help..
 
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think if you put an onclick on the link and just return false it'll do it. Put your condition in the onclick event and if the condition fails just return false.
 
Steve Renard
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry..It doesn't work.
Basically I'm able to click the link and it takes me to another page.
I don't want that to happen.
Actually I want the link to be deactivated on meeting the condition.
do I need to set some property to false..?
 
Rob Hunter
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried simply making a link and putting return false in the onclick and it worked. Post the href line you're using so we can take a look. Return false will cancel out the click.
 
Steve Renard
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<a href="knv.jsp" onklick="clicked()" >Known Values"<a/>"
replaced c with k in onclick I had problems posting this message
I put the condition inside clicked()as you said.
Pls give me the correct format with an example.
 
Rob Hunter
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where you call the clicked() method before that put return. If in the function you say return false then that will be returned for the function only. The return I mention here is the return to the click event. So, therefore klicked="return clicked();". In the function to cancel the click you will have to return false as well.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Steve Renard:

Pls give me the correct format with an example.



Steve, please be sure to use real words when posting to the forums: "Please" as opposed to "Pls".

The format that is being referred to is:



Returning false from inside a function called from onclick will not have the same effect.

[ April 27, 2007: Message edited by: Bear Bibeault ]
[ April 27, 2007: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That, however, will not help you did this in a dynamic fashion.

To alter the onclick handler under script control after the page is loaded, you'll need to do something like:

 
Steve Renard
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great..
Thanks a lot Rob and Bear.
It works well. I got it now.
I have one more question.How to pass dynamic parameters as query strings with a link?

<a href="knv.jsp" onklick="return clicked()" >Known Values</a>
I'm selecting a value from a dropdown. I need to pass this dynamic value to another page.
 
Rob Hunter
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've just done this in the past (Bear probably has a better way) just build up your URL in the javascript and the use document.location to redirect to the page but doing this just make sure you return false to the href onclick all the time so there aren't 2 redirects atempts happening. Bear might suggest using getElementById and doing something with the URL but I've just used this way.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Steve Renard:
I have one more question.How to pass dynamic parameters as query strings with a link?



Usually it's best to start a new topic for new questions.

I'm selecting a value from a dropdown. I need to pass this dynamic value to another page.



Why are you not simply submitting the form containing the dropdown element?
 
Rob Hunter
Ranch Hand
Posts: 838
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Bear suggested, just submit the form. Once back in the JSP you can just build your URL and send a redirect there before touching any subs within the JSP or do the javascript buildup if a different page.
 
Steve Renard
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob,
Can you elaborate on your answer?
I have a set of links in my page that are not wrapped inside form tag.
How do I go abt this?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Steve Renard:

How do I go abt this?



Once again, please be sure to use real words when posting. "abt" is not a word.

It doesn't matter that the links are outside the form; the select element is in a form, is it not?

You can cause the form to be submitted under script control with:

 
Steve Renard
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob and Bear for your help.
Really appreciate it.
I managed to get that working.
 
No matter. Try again. Fail again. Fail better. This time, do it with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic