How to enable a disabled button by clicking on another button?

user2565280 picture user2565280 · Jul 11, 2013 · Viewed 48k times · Source

I have two buttons:

<button onclick=initialize() id="1" data-role="button" data-mini="true" data-corners="false" data-theme="b">Show My Position</button>
<button onclick=calcRoute() id="2" data-role="button" data-mini="true" data-corners="false" data-theme="b">Evacuate !</button>

I want to have the second button disabled by default, and have it enabled if clicking on the first button. How do I accomplish this?

Answer

Idan Adar picture Idan Adar · Jul 11, 2013

Please see the following answers to questions:

The simplest approach would be (just a pure example w/out taking into consideration browsers, etc):

<html>
<head>
    <script>
        function enableButton2() {
            document.getElementById("button2").disabled = false;
        }
    </script>
</head>
<body>
    <input type="button" id="button1" value="button 1" onclick="enableButton2()"  />
    <input type="button" id="button2" value="button 2" disabled />
</body>
</html>