Make input section required when both checkboxes are selected

前端 未结 3 1123
孤城傲影
孤城傲影 2021-01-29 09:11

So I have two checkboxes when clicked separately, will make the bottom section required - How can I make it that the last section is required when both are checked? I can\'t see

3条回答
  •  我在风中等你
    2021-01-29 09:35

    I see you're using jQuery, so here's a jQuery-based solution.

    First, you can combine the change event handler for both inputs.

    Second, you can use .prop("checked") to find the checked state of your checkboxes.

    Finally, use .prop("required", true/false) to set the required state of your last checkbox.

    Here's how I went about it:

    $(document).ready(function()
    {
        $("#rtd3Transaction, #rtd3Device").change(function()
        {
            var required = $("#rtd3Transaction").prop("checked") && $("#rtd3Device").prop("checked");
            $(".rtdConfirm").prop("required", required);
        });
    });
    

提交回复
热议问题