JQuery validation-select required if checkbox checked

后端 未结 4 571
北荒
北荒 2020-12-05 02:22

using jquery I want to make a selection from a select box required (ie it can\'t be left as the blank default) if a particular checkbox is ticked. My code:

$         


        
4条回答
  •  眼角桃花
    2020-12-05 02:57

    This works like a charm

    inputname:
    {
        required: function(){
            if($("select[name=inputname]").val() == 1){
                return true;
            }
            else
            {
                return false;
            }
        }
    }
    

    You can edit the inputname to yours prefered.

    To change it to input field, you can change the select part to input

提交回复
热议问题