Since IE (<8?) does not let me change the text color of a disabled button, and introduces a horrible shadow (embossed effect), I want to mimic the behaviour of being a disabled button. This button will be disabled if there are input errors on the form.
Instead of disabling I can change the class in JS to darken the button etc when form validation takes place. What I also want to do is make it unclickable as well so that the user can not submit the form. (How) can I do this?
Thanks
A disabled button is unusable and un-clickable. The disabled attribute can be set to keep a user from clicking on the button until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the button clickable again.
How do I make a link non-clickable? In order to disable a HTML Anchor Link (HyperLink), the value of its HREF attribute is copied to the REL attribute and the value of HREF attribute is set to an empty JavaScript function. This makes the HTML Anchor Link (HyperLink) disabled i.e. non-clickable.
To disable a button using only JavaScript you need to set its disabled property to false . For example: element. disabled = true . And to enable a button we would do the opposite by setting the disabled JavaScript property to false .
Definition and Usage. The <button> tag defines a clickable button. Inside a <button> element you can put text (and tags like <i> , <b> , <strong> , <br> , <img> , etc.). That is not possible with a button created with the <input> element!
This won't solve your issue since you're using < IE10, but for those who are using modern browsers and to answer the original question:
html button not clickable without being disabled
...this works simply & elegantly:
.no-click {
pointer-events: none;
}
Just add this class to your UI:
<button class="no-click">
<form onSubmit="return validate(this)"
Just return false to stop submission
you can add the function in the window.onload too:
window.onload=function() {
document.getElementsByTagName("form")[0]).onsubmit=function() {
return validate(this);
}
}
function validate(theForm) {
// if not valid
return false;
// else
return true;
}
If you want to adhere to the newest best practices, you will use addEventListener or attachEvent or jQuery bind
Comment From @BrendanEich :
@mplungjan onclick of submit just falls out of that being a button; form onsubmit is clearly better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With