Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 513
user2565280 Avatar asked Jul 11 '13 03:07

user2565280


People also ask

How do I enable a Button after clicking?

Enable / Disable submit button $("#btnSubmit"). attr("disabled", true); 1.2 To enable a disabled button, set the disabled attribute to false, or remove the disabled attribute.


1 Answers

Please see the following answers to questions:

  • Disable Buttons in jQuery Mobile
  • How to disable html button using JavaScript?

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>
like image 59
Idan Adar Avatar answered Oct 12 '22 10:10

Idan Adar