How to Enable and Disable Buttons

user3217574

I have 4 buttons. Once on the page, I only want button 1 to show. Once button 1 has been clicked, it disappears and only button 2 is visible. Once button 2 has been clicked, it disappears and only button 3 shows. The same thing happens for button 5. Any help would be appreciated.

<html>
<script>
    function enableButton2() {
        document.getElementById("button2").disabled = false;
    }
function enableButton3() {
        document.getElementById("button3").disabled = false;
    }
function enableButton4() {
        document.getElementById("button4").disabled = false;
    }
function enableButton5() {
        document.getElementById("button5").disabled = false;
    }
</script>
</head>
<body>
    <input type="button" id="button1" value="button 1" onclick="enableButton2()"                  
    onclick="hidden" />
<input type="button" id="button2" value="button 2" disabled onclick="enableButton3()"   
    onclick="hidden" />
<input type="button" id="button3" value="button 3" disabled 
    onclick="enableButton4()" onclick="hidden"  />
<input type="button" id="button4" value="button 4" disabled onclick="enableButton5()" 
    onclick="hidden" />

Barmar

There's no need for a different function for each button. Make the ID of the next button a parameter of a single function. And to hide the first button, you need to set its display style, so pass this as another argument.

HTML:

<input type="button" id="button1" value="button 1" onclick="enableButton(this, 'button2')" />
<input type="button" id="button2" value="button 2" disabled onclick="enableButton(this, 'button3')" />
<input type="button" id="button3" value="button 3" disabled onclick="enableButton(this, 'button4')" />
...

JS:

function enableButton(thisButton, nextButton) {
    thisButton.style.display = "none";
    document.getElementById(nextButton).disabled = false;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to enable /disable buttons in jquery?

From Dev

How to Create Buttons With Disable Enable Option in NSIS?

From Dev

How to enable/disable Bootstrap buttons remotely using jquery?

From Dev

How to disable/enable multiple upload buttons with multiple checkboxes

From Dev

How can I enable/disable a UITextField's inputAccessoryView buttons?

From Dev

How to enable and disable buttons in a gridview in asp.net

From Dev

Javascript to disable or enable radio buttons

From Dev

Javascript to disable or enable radio buttons

From Dev

PHP daily disable / enable buttons

From Dev

Disable and enable buttons using variables

From Dev

enable/disable radio buttons in AngularJS

From Dev

Enable/Disable Group Buttons at the same time in JavaFX

From Dev

Enable or disable primefaces datatable buttons at the certain row

From Dev

Function for enable and disable dynamic buttons(FileSystemWatcher)

From Dev

Enable and disable text with radio buttons with javascript?

From Dev

How to enable / disable a Preference?

From Dev

How to enable or disable services?

From Dev

How to enable or disable services?

From Dev

How to enable / disable a Preference?

From Dev

How to enable/disable a checkbox

From Dev

How to enable disable a select drop down list using radio buttons with angularjs?

From Dev

VB .net: How to disable/enable buttons depends who's logged in (admin account vs. ordinary account)

From Dev

VB .net: How to disable/enable buttons depends who's logged in (admin account vs. ordinary account)

From Dev

Javascript can disable/enable buttons but can't disable radio buttons or text areas

From Dev

How to disable TableTools buttons in DataTables?

From Java

How to enable/disable inputs in blazor

From Dev

How to disable and enable keyboard in ubuntu?

From Dev

How to enable and disable qDebug() messages

From Dev

How to disable/enable prefetching in GCC?

Related Related

  1. 1

    How to enable /disable buttons in jquery?

  2. 2

    How to Create Buttons With Disable Enable Option in NSIS?

  3. 3

    How to enable/disable Bootstrap buttons remotely using jquery?

  4. 4

    How to disable/enable multiple upload buttons with multiple checkboxes

  5. 5

    How can I enable/disable a UITextField's inputAccessoryView buttons?

  6. 6

    How to enable and disable buttons in a gridview in asp.net

  7. 7

    Javascript to disable or enable radio buttons

  8. 8

    Javascript to disable or enable radio buttons

  9. 9

    PHP daily disable / enable buttons

  10. 10

    Disable and enable buttons using variables

  11. 11

    enable/disable radio buttons in AngularJS

  12. 12

    Enable/Disable Group Buttons at the same time in JavaFX

  13. 13

    Enable or disable primefaces datatable buttons at the certain row

  14. 14

    Function for enable and disable dynamic buttons(FileSystemWatcher)

  15. 15

    Enable and disable text with radio buttons with javascript?

  16. 16

    How to enable / disable a Preference?

  17. 17

    How to enable or disable services?

  18. 18

    How to enable or disable services?

  19. 19

    How to enable / disable a Preference?

  20. 20

    How to enable/disable a checkbox

  21. 21

    How to enable disable a select drop down list using radio buttons with angularjs?

  22. 22

    VB .net: How to disable/enable buttons depends who's logged in (admin account vs. ordinary account)

  23. 23

    VB .net: How to disable/enable buttons depends who's logged in (admin account vs. ordinary account)

  24. 24

    Javascript can disable/enable buttons but can't disable radio buttons or text areas

  25. 25

    How to disable TableTools buttons in DataTables?

  26. 26

    How to enable/disable inputs in blazor

  27. 27

    How to disable and enable keyboard in ubuntu?

  28. 28

    How to enable and disable qDebug() messages

  29. 29

    How to disable/enable prefetching in GCC?

HotTag

Archive