can I change the value of a checkbox using a Java script in the DOM of the browser page?
It is necessary that the value remains the next time the form is loaded.
I tried several methods, but it only worked to visually check the box. When you clicked again, the checkbox was updated to a real one, and when submitting the form, a message was displayed that there was no checkmark at all
2
Answers
did you try using an if statement to check/change the value?
something like this could work:
(i just used 0 and 1 as an example)
You want to be able to set the checkbox. Here’s a function that I named
toggle
which receives a checkbox element and a value and if the value is'checked'
then it checks the checkbox, otherwise it unchecks it.So, when you load your form and it gets clear what to do with the checkbox, just trigger
toggle
with the right parameters.