Search code examples
twitter-bootstrapcheckboxdisabled-control

How to disable or enable a bootstrap submit button if checked checkbox


I need to enable or disable a bootstrap submit button on a form if a checkbox is cheched or not

echo "<div class='panel panel-danger'><div class='panel-heading'>OBSERVACIONES</div><div class='panel-body'>";
echo "<div class='input-group'>";
echo "<label class='checkbox-inline'><input type='checkbox' name='visto' id='visto' value=''> Visto bueno del Responsable</label>";
echo "</div>"; 
echo "</div>"; 

...

echo "<input type='submit' class='btn btn-primary' value='SAVE' name='grabaperaus' formaction='update.php'>";

Solution

  • For the checkbox all you need to do is get the Id of your submit button (grabaperaus in this case) disable it onChange event of the checkbox.

    <input type="checkbox"  
    onchange="document.getElementById('grabaperaus').disabled = !this.checked;" name='visto' 
    id='visto'/>