aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Disable a link when it clicks once, using javascript 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 when it clicks once, using javascript" Watch "Disable a link when it clicks once, using javascript" New topic
Author

Disable a link when it clicks once, using javascript

kavita vala
Ranch Hand

Joined: Jul 22, 2010
Posts: 42
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

Joined: May 02, 2010
Posts: 105
Try this

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

Javascript is :


Is this information useful for you


Wake up! Don't let your smile be snatched away by anybody!
Regards, Eswar
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

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.


Love all, trust a few, do wrong to none.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

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

Joined: Sep 15, 2009
Posts: 806

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

Joined: Sep 15, 2009
Posts: 806

I am sorry Eswara, what you coded is right. I haven't noticed the scope of the clickCount variable.
kavita vala
Ranch Hand

Joined: Jul 22, 2010
Posts: 42
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

Joined: Sep 15, 2009
Posts: 806

It is simple.

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Apr 06, 2010
Posts: 4467
    
    8

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

Joined: Sep 15, 2009
Posts: 806

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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Sep 15, 2009
Posts: 806

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

Joined: Sep 29, 2008
Posts: 12617

Why are you keeping track of the number of clicks?
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Sep 15, 2009
Posts: 806

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.
 
 
subject: Disable a link when it clicks once, using javascript