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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 541
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: 267
    
    4

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: 541


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: 18113
    
    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: 267
    
    4

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
Ranch Hand

Joined: Aug 06, 2010
Posts: 359
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: Java EE 6 Web Component Developer
Oracle Certified Expert: Java EE 6 Enterprise JavaBeans Developer
Monica. Shiralkar
Ranch Hand

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

I found a way to do it.



Calling the above code at the start of Jquery did the trick.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to make an HTML button such that what ever it does it does only once and not again.
 
Similar Threads
action class gets skipped when opening link via javascript
How to Show the ProgressBar in the browser when i am doing Complex Operation on server
Events getting fired multiple times with one click
How to have a button set a bean value
Struts 2 with JQuery tab