make a input field required if radio is checked

前端 未结 3 1173
礼貌的吻别
礼貌的吻别 2021-01-01 23:53

Can I somehow insert the required attribute into an input field only if a certain radio is checked?

I have an input field named \"ladder-meters\" that is not require

3条回答
  •  [愿得一人]
    2021-01-02 00:15

    Tried F. Orvalho, didn't work for me, I had to use

    $('#ladder').change(function () {
        if(this.checked) {
            $('#ladder-meters').prop('required', true);
        } else {
            $('#ladder-meters').prop('required', false);
        }
    });
    

    It could be usefull. Thx to F. Orvalho for the structure

提交回复
热议问题