aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How to make an HTML button such that what ever it does it does only once and not again. 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 "How to make an HTML button such that what ever it does it does only once and not again." Watch "How to make an HTML button such that what ever it does it does only once and not again." New topic
Author

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

Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 663
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

Joined: Nov 06, 2012
Posts: 297
    
    5

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?


Read my books: Hello! HTML5 & CSS3 | HTML5 in Action | Read my blog
Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 663


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
Bartender

Joined: Oct 14, 2005
Posts: 18904
    
    8

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

Joined: Nov 06, 2012
Posts: 297
    
    5

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

Joined: Aug 06, 2010
Posts: 543
    
    4

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.


Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 663
Thanks all.

I found a way to do it.



Calling the above code at the start of Jquery did the trick.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to make an HTML button such that what ever it does it does only once and not again.