Home > Mobile >  How to disable button when check box is unchecked
How to disable button when check box is unchecked

Time:08-12

I have one check-box for terms and services and one button, initially the check box will be checked but if someone uncheck the check box I want to disable the button so the user cannot proceed further, please let me know how I can achieve this, thanks in advance.

CodePudding user response:

Something like this would do the trick:

    import { useState } from "react";
    
    export default function App() {
      const [disableButton, setDisableButton] = useState(false);
      const toggleDisableButton = () => {
        setDisableButton(!disableButton);
      };
      return (
        <div className="App">
          <input
            type="checkbox"
            id="demo"
            name="demo"
            value="demo"
            onChange={toggleDisableButton}
          />
          <button disabled={disableButton}>button</button>
        </div>
      );
    }

  • Related