lundi 2 octobre 2017

How to disable anPHP disable and clear textbox when checkbox is unchecked. Check/uncheck checkbox depending on database

I want to disable and clear a textbox if a checkbox is uncheck and enable it when checked. At the same time, the checkbox should be dependent on the value on the database.

  • If deductstatus == 1, checkbox should be checked when loaded
  • If deductstatus == 2, checkbox should be unchecked when loaded

The code below is not working. Any help?

$(".dedstat").click(function() {
  if ($(".dedstat").is(":checked")) {
    $(".deductto").removeAttr("disabled")
  } else {
    $(".deductto").attr("disabled", "disabled")
    var deductto = document.getElementById("deductto");
    deductto.value = "";
  }
});
<script src="http://ift.tt/1oMJErh"></script>
<input type="checkbox" name="dedstat" id="dedstat" value="<?php if ($dedstat == 1) echo 'checked'; ?>">
<input type="text" name="deductto" id="deductto" value="<?php echo $deductto;?>">



Aucun commentaire:

Enregistrer un commentaire