The html button is not available without disabling

Since IE (<8?) Does not allow me to change the text color of the disabled button and introduces a terrible shadow (embossing effect), I want to reproduce the behavior of the disable button. This button will be disabled if there are input errors in the form.

Instead of disconnecting, I can change the class in JS to darken the button, etc., when a form check occurs. What I also want to do also makes it invisible so that the user cannot submit the form. (How can i do this?

thanks

+6
source share
4 answers

Answer of IE10 + and modern browsers

This will not solve your problem since you are using <IE10, but for those who use modern browsers and answer the original question:

The html button cannot be pressed without shutting down.

... it works simply and elegantly:

.no-click { pointer-events: none; } 

Just add this class to your interface:

 <button class="no-click"> 
+11
source
 <form onSubmit="return validate(this)" 

Just return false to stop sending

you can add a function to 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 follow the latest best practices, you will use addEventListener or attachEvent or jQuery bind

Comment by @BrendanEich :

@mplungjan onclick submit just drops out of this button; the onsubmit form is clearly better.

+2
source

Nothing goes beyond this decision. First of all, re-enable your button, and then using jQuery, addClass you want (you can also remove the old class), then re-disable the button:

 $("#yourbuttonid").click(function(){ $(this).removeAttr("disabled").removeClass("classname").addClass("classname2").attr("disabled", "disabled"); }); 
0
source

You need to return false from the onclick event:

 <input type="submit" value="Submit" onclick="return test();" /> 

or

 <input type="submit" value="Submit" onclick="return false;" /> 

NOTE: you must use return in onclick.

-3
source

Source: https://habr.com/ru/post/894030/


All Articles