0

I have designed a web page which consists of 12 button of type image.After clicking on each button it retrive a question from database using servlet and display it on the web page.I want to the disable the buttons after they are clicked.I tried using .diabled=true but its not working.And the button are "NOT" in the "FORM".Can anybody help me??I using JSP,Servlet and javascript.

  • you want to disable using javascript? – CJ Ramki Feb 28 '14 at 06:52
  • you have to use session/cookies to store which buttons were clicked, then probably give a css class to the clicked ones and use javascript to block clicking them using preventDefault() or onclick="return false;" – SajithNair Feb 28 '14 at 06:56

3 Answers3

2

For XHTML <input type="button" disabled="disabled" /> is the valid markup.

For HTML5 <input type="button" disabled /> is used by W3C in their samples.

disabled is a Boolean attribute and hence can be assigned true or false

foo.disabled = true;

Also in theory you can set foo.setAttribute('disabled', 'disabled'); but it can not be trusted for IE.

For more details read this thread How to disable html button using JavaScript?

Community
  • 1
  • 1
Gaurav
  • 1,078
  • 2
  • 8
  • 18
1

use diabled="disabled" instead of disabled=true

Bijaya Khadka
  • 159
  • 3
  • 6
  • 20
0
var button = document.getElementById('btn');
button.addEventListener('click', function(){
    if(this.disabled === true){
        return;
    }
    alert('request the data');
    this.disabled = true;
})

http://jsfiddle.net/canvast/F7Gd2/1/