Make input section required when both checkboxes are selected

前端 未结 3 1149
孤城傲影
孤城傲影 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:17

    LOL, didn't I say to only use one $(document).ready() function?

    Anyway, just combine the two conditionals into a third change function.

    /* Make checkbox textboxes not required unless checked */
    $(document).ready(function() {
        $('#rtd3Transaction').change(function() {
            if ($('.rtdConfirm').attr('required')) {
                $('.rtdConfirm').removeAttr('required');
            }
            else {
                $('.rtdConfirm').attr('required','required');
            }
        });
    
        $('#rtd3Device').change(function() {
            if ($('.rtdConfirm').attr('required')) {
                $('.rtdConfirm').removeAttr('required');
            }
            else {
                $('.rtdConfirm').attr('required','required');
            }
        });
    
        $('#rtd3Transaction, #rtd3Device').change(function() {
            if ($('#rtd3Transaction').checked && $('#rtd3Transaction').checked) {
                $('.rtdConfirm').attr('required','required');
            }
            else {
                $('.rtdConfirm').removeAttr('required');
            }
        });
    });
    

    If that doesn't work, post the rest of your code and I'll see what I can do.

提交回复
热议问题