Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Disable a link when it clicks once, using javascript

 
kavita vala
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a hyper link which is click and then i want to disable it with the help of javascript



Once i click on Investor Listing and then i want to disable it

Please help me.
 
Eswar Nec
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this

call the javascript onclick="return disableMeAfterOnceClick()" during onclick the link

Javascript is :


Is this information useful for you
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this wont work Mr. Eswara because, each time the link is clicked the variable clickCount will be initialized to 0. So every time it returns zero.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this wont work Mr. Eswara because, each time the link is clicked the variable clickCount will be initialized to 0. So every time it returns true.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ms. Kavitha, try this one. Create a hidden field named clicked and initialize its value to 0.

<input type=hidden id=clicked value=0>

for the first time if you click make the value in the hidden filed as 1. The next time you click check the value of hidden filed, if it is 1 then it is already clicked. This time you will get false;

Hope this helps you.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry Eswara, what you coded is right. I haven't noticed the scope of the clickCount variable.
 
kavita vala
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replay but i have not a single link.
I have 3 links in my program to handle that's why i want some built in property
to disable link for temporary.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is simple.

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why on earth would you use a form element for this? Just use a variable. I don't know why a count is needed at all, though.
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From a usability point of view, wouldn't it make more sense to change the link into plain text (manipulate the DOM to strip the <a> tags) rather than disabling the link? Otherwise you end up with confused users wondering why your link doesn't work any more, despite looking like it can still be clicked.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mr. David, I forgot to remove that count variable. However I edited it and removed.

Coming to the point, I gave the sample code with the knowledge I have. Can you please tell me how can it be done without using form elements so that I can improve.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a variable.

But I don't understand what the count is for at all; I didn't see anything that required tracking how many times a link was clicked.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:Use a variable.


Can you please tell me how? I am not asking the code. I am asking the way.

With the knowledge I have I created another logic for this. Tell me whether this is correct or not.

I will create 3 variables. For each and every click I will increment the appropriate variable. Ex: link1--var1

But this is not good logic because if the links goes on increase the variables increase. So I think form elements is right way. What do you say?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you keeping track of the number of clicks?
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:Why are you keeping track of the number of clicks?


I don't know, it's Ms. Kavita's requirement. She asked, I proposed a logic.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nobody said anything about tracking the number of clicks; only the proposed solutions included it, and so far, I don't know why.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good question Mr. David. Coming to my point, I am a learner, I want to solve problems or at least try to figure the solution out. So I was eager to answer the question.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic