Good morning,
I have a small piece of Javascript that checks a checkbox automatically based on the value of a drop-down menu. For simplicity purposes let's say that the checkbox gets checked when the value of a drop-down menu is "something". The checkbox is required.
The issue that I'm running into is that when you allow the "required" error to show on the checkbox on purpose, say by trying to submit the form without checking the box, the error for "Value is required" as expected. Then when I switch the drop-down to the value "something", the checkbox is checked, but the error persists.
The form will submit without issues, but I would like for the required error to be removed, to avoid confusion.
I tried to trigger the change, but that didn't work. Any ideas? Below is my simple code and screenshot.
UPDATE: I'm trying trigger the click as well, not sure if that's the right approach.
$( document ).ready(function() { $(document).on('change blur', '.dropdown select', chkBoxRA); function chkBoxRA () { var dropdown = $('.dropdown select').val(); if (dropdown == 'something') { $('#Field1-0').attr("checked", true); $('#Field1-0').prop("checked", true); } $('#Field1-0').trigger("change"); } });