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

osbragon picture osbragon · Jun 23, 2016 · Viewed 12.1k times · Source

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'>";

Answer

Coding Enthusiast picture Coding Enthusiast · Jun 23, 2016

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'/>