Make input section required when both checkboxes are selected

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

    In JS you may use the onchange event on the parent that holds the check boxes, hopefully a form, and check if both check boxes are checked, if they do set the third check box to required

    const rtd3Transaction = document.querySelector('#rtd3Transaction');
    const rtd3Device = document.querySelector('#rtd3Device');
    const rtdConfirm = document.querySelector('#rtdConfirm');
    
    document.querySelector('form').addEventListener('change', ()=> {
      if(rtd3Transaction.checked && rtd3Device.checked) {
        rtdConfirm.required = true;
      }
    })
    

提交回复
热议问题