Reputation: 93
I have an image as a button..I want to disable the image onclick...How can I do that?
<input type="image" src="someimage.png" height="20px" width="20px" name="button" />
Upvotes: 3
Views: 13945
Reputation: 1479
html(add id):
<input id="btn" type="image" src="someimage.png" height="20px" width="20px" name="button" />
js:
document.getElementById("btn").onclick = function(){
this.disabled = true
}
Or you can just add attribute onclick="this.disabled = true"
update for comment:
You can use CSS rule :disabled
for styling disabled buttons
P.S. pseudo-class :disabled only for modern browsers(not for IE8-).
Upvotes: 5
Reputation: 126
You can use
<button height="20px" width="20px" name="button"><img src="someimage.png"/></button>
and now you can disable button as normal as everything
Upvotes: 0
Reputation: 1456
Unless you have a specific reason to use the input type, you shouldn't be using it for image.
<img src="smiley.gif" alt="Smiley face" height="42" width="42">
use the image type, and no onclick handler.
Upvotes: 1