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.
Asked
Active
Viewed 453 times
0
-
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 Answers
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?
0
var button = document.getElementById('btn');
button.addEventListener('click', function(){
if(this.disabled === true){
return;
}
alert('request the data');
this.disabled = true;
})

canvast
- 1