View Full Version : Disable <a class button if input fields empty

10-16-2015, 02:14 AM
I know it's easy to do using <button> or <input type="submit" but how would you keep this button disabled unless both input fields are filled?

<input id="one" type="text">
<input id="two" type="text">
<a href="#" class="button">OK</a>

10-16-2015, 04:39 AM
Disable and href? Maybe you could preventDefault / return false; or remove the href attribute with removeAttribute('href') ?

Or how about hiding the link with style.display='none'; and when the input is filled, show it with style.display='block';

10-16-2015, 04:28 PM
Thank you. I got some help over on stackoverflow. Similar to what you suggested.

$('#one, #two').blur(function() {
if($('#one').val() !== "" && $('#two').val() !== "") {
} else {

And then you just do the button as <a class="button">OK</a>