Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make an HTML button such that what ever it does it does only once and not again.

 
Monica Shiralkar
Ranch Hand
Posts: 866
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an HTML button. On clicking it it should display AJAX response. It does it correctly. But if click this button again it displays the response once again below it.

How to make an HTML button such that what ever it does it does only once and not again.

Thanks.
 
Rob Crowther
author
Ranch Hand
Posts: 297
5
Android Fedora Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, whatever you're doing the first time the button is clicked, don't do it the second time. I'm not sure exactly what you're having difficulty with here?
 
Monica Shiralkar
Ranch Hand
Posts: 866
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I do not want to restrict the user from clicking the button again.

I'm not sure exactly what you're having difficulty with here?


If the user clicks button it should display some information. Now if the user clicks this button again it should not keep displaying this information once again below it and so on.

thanks
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So if I understand you correctly, you don't want the button to be grayed out, but when the user clicks on it, you want it to do nothing?

I don't think that's good usability. Buttons which don't do anything are confusing to users. In my opinion it would be better to disable the button after the user clicks it once. That shows the user that there is no point in clicking it again.
 
Rob Crowther
author
Ranch Hand
Posts: 297
5
Android Fedora Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Monica. Shiralkar wrote:I do not want to restrict the user from clicking the button again.


I never suggested you should, I said change the behaviour of the button.

Monica. Shiralkar wrote:If the user clicks button it should display some information. Now if the user clicks this button again it should not keep displaying this information once again below it and so on.


Then don't. This displaying of information is not some natural behaviour of HTML that you're fighting against, it's a behaviour you've implemented. Your code is what is "displaying this information once again below", add a condition to your code so it doesn't.

If you want help with your code then you'll have to post it, we can't guess what your code is.
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're adding a div or a span element on your ajax callback, I assume. In this case, just check if that div is already there, and if so, don't do the ajax call. Either that or replace the div instead of adding it.

Think about it. How would you do this? You can do it in a thousand ways.
 
Monica Shiralkar
Ranch Hand
Posts: 866
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all.

I found a way to do it.



Calling the above code at the start of Jquery did the trick.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic