lundi 24 février 2020

Javascript for toggle checkbox - Laravel

Hello guys I'm new to Laravel and programming, I'm trying to let the checkbox checked if the value of $status is 1, in my scenario below the value of should be 1 so the checkbox should be checked but its not working.

Javascript

<script>
function sta() {
  var st = document.getElementById("status").value;
  var checkbox = document.getElementById("status");

  if (st == 1) {
        checkbox.checked == true;
  } else {
        checkbox.checked == false;
  }
}
</script>

HTML

<body onload= "sta()">

<form id="ed" name="ed" method="post" action="">
    
    <input type="hidden" name="_method" value="PATCH" />
        <div class="form-group">Name:
     <input type="text" name="name" class="form-control" value="" placeholder="Enter Name" />
        </div>
        <div class="form-group">Description:
                    <input type="textarea" name="description" class="form-control" value="" 
                    placeholder="Enter Description" />
        </div>

//from here is the checkbox code

            <div class="form-group">Status Type:
                <label class="radio-inline">
                   <input type="checkbox" id="status" name="status" value="">
               </label>
             </div>



Aucun commentaire:

Enregistrer un commentaire