Search code examples
javascriptcssbuttondisabled-input

Button disabled before action?


I have two buttons. I want the second button to be disabled until the first button is clicked. How can I do this with JavaScript and CSS?


Solution

  • Here you go

    document.getElementById('btn1').addEventListener('click', function() {
        document.getElementById("btn2").disabled = false;
    });
    

    HTML:

    <input type="button" id="btn1" value="button 1" />
    <input type="button" disabled="disabled" id="btn2" value="button 2" />
    

    Tested in Chrome.

    Fiddle: http://jsfiddle.net/b41oskm4/