vendredi 4 janvier 2019

How to prevent jquery element from accepting input / changes but still sending data on POST (without using a hidden element)?

I have a checkbox $(#myinput) and based on selection of a few combinations of other options, I would like this checkbox to be enforced as checked or enforced as unchecked.

If I use $(#myinput).prop("disabled", true) however, then the value of the checkbox will not be submitted in a generated POST request. Since it is a checkbox, readonly has no effect... that is, readonly does not control whether the input can experience a state change to be toggled on or off via clicking.

Without using a hidden element, what is the best way to make $(#myinput) unchangeable by the user's clicks, but also ensure that whatever value it is frozen with is still submittable via any form submissions / POST requests?

I'm looking for modifying only settings of the checkbox itself, and not adding complexity with a hidden element. Please only add answers if they avoid creating hidden elements.




Aucun commentaire:

Enregistrer un commentaire