0

I have a form with an if statement, where in the case where a user has completed all the form related to the part of the registry, all the fields of the form, must be disabled.

The only field that I can't disable is the checkbox. Here is my code for disabling the other fields:

<?php if ($stato_ut=="REG"){  ?>
not complete
<?php }else{ ?>
<script type="text/javascript">
    $(document).ready(function(){
        $("#dati_utente :input").prop("disabled", true);
        $("#dati_utente :button").hide();
    });
</script>

#dati_utente is the id for the form

checkbox input:

<input <?php if (!(strcmp($row_user_fe['disp_trasferimento_ut'],"S"))) {echo "checked";} ?> name="disp_trasferimento_ut" type="checkbox" id="disp_trasferimento_ut" value="S" data-plugin="switchery" data-color="#1bb99a"/> 

All other fields are disabled correctly, how can I disable the checkbox?

cssyphus
  • 37,875
  • 18
  • 96
  • 111
usss
  • 1
  • What you are tryng to do `$("#dati_utente :input")`? – brk Mar 26 '19 at 15:50
  • 1
    Possible duplicate of [jQuery - checkbox enable/disable](https://stackoverflow.com/questions/2330209/jquery-checkbox-enable-disable) – Elias Mar 26 '19 at 15:53
  • Did the demo in my answer work for you? If it did, but your code still does not work, then the problem likely has to do with how you are selecting the checkbox. In other words, you are probably not actually connecting with it (your method of selecting the checkbox is probably not working). See [**this other answer**](https://stackoverflow.com/questions/55345191/how-to-fix-the-margin-page-to-the-left/55345569#55345569) for more info about how to solve this yourself. You can then update your original question with more information (based on your investigations using DevTools) -- **edit** link. – cssyphus Mar 26 '19 at 16:30
  • Hi - just following up. Was your question answered satisfactorily? If there is more we can help with, please add a comment below one of the answers, or edit your question to clarify what else you need help with. Otherwise, it would be great if you could choose a "best answer" (by clicking the checkmark beside the answer) to close out the question. If no answer provided helpful information, please add your own answer and select that as the best answer. You won't get any points for doing so, but that will close out the question. *Thanks!* – cssyphus Apr 03 '19 at 19:44

2 Answers2

0

Your code its right but call it via id.

$("#disp_trasferimento_ut").prop('disabled',true);
$("#disp_trasferimento_ut2").attr('disabled',true);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" id="disp_trasferimento_ut" name="withProp"> With PROP
<input type="checkbox" id="disp_trasferimento_ut2" name="withAttr">With ATTR
Arm144
  • 721
  • 1
  • 10
  • 23
0

Your code works for me, but isn't exactly correct. Try it like this:

$("#dati_utente input").prop("disabled", true);

Demo:

$('button').click(function(){
  $("#dati_utente input").prop("disabled", true);
});
input{transform:scale(2);}
div{margin:10px;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

<div id="dati_utente">
  CB: <input id="disp_trasferimento_ut" type="checkbox" />
</div>

<button>Disable Checkbox</button>
cssyphus
  • 37,875
  • 18
  • 96
  • 111