I have a form in which I added a check box with the following code (see below) but I can not get it to work, could someone please tell me if the code has anything else?
You should change the input event of:
onclick="enableSending()"
a
onchange="enableSending()"
You can try this:
function enableSending(){
let btn = document.getElementById("enviar");
let checkbox = document.getElementById("terms");
btn.disabled = !checkbox.checked;
}
<div class="terms">
<input type="checkbox" name="terms" id="terms" onChange="enableSending()">
<label for="terms">Al enviar este mensaje prestas expresamente consentimiento al tratamiento de sus datos personales. He leido y acepto la <a href="#" targer="_blank">Política de Privacidad</a></label>
</div>
<input type="submit" value="Enviar" id="enviar" disabled="disabled">
If you notice, create a input type submit disabled to try. I imagine according to your js that you are trying to enable the submit button when you accept the "terms and conditions" . The checkbox calls the enableSending function for the change event and not for the click as the checkbox changes from status and it is better to evaluate them by "when they change their status or value" that is the change . Then in the enableSending function invoke the checkbox and the input by the id , you can call it as you were doing but since you did not specify the html of your form, I limited it to add a id and invoke them for that attribute, but the desired effect is the same, you can guide this example I hope it works for you.
Greetings