Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html button not clickable without being disabled

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

like image 689
andrew Avatar asked Aug 01 '11 14:08

andrew


People also ask

Why is my HTML button not clickable?

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 HTML element not clickable?

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.

How do you inactive a button?

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 .

How do I make a button clickable in HTML?

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!


2 Answers

IE10+ & Modern Browsers Answer

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">
like image 137
jusopi Avatar answered Sep 20 '22 12:09

jusopi


<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.

like image 38
mplungjan Avatar answered Sep 22 '22 12:09

mplungjan