There is a form and input text. It is necessary that by typing the text in the form to make an inactive select and vice versa, i.e. one out of two.

function checkParams() { var time = $('#time').val(); if (time.length == 0) { $('#time_of_day').removeAttr('disabled'); } else { $('#time_of_day').attr('disabled', 'disabled'); } $("#time_of_day").on('change', function() { if ($(this).val() == 'Утром' || $(this).val() == 'Днём' || $(this).val() == 'Вечером' || $(this).val() == 'Ночью') { $('#time').attr('disabled', 'disabled'); } else { $('#time').removeAttr('disabled'); } }); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select name="time_of_day" id="time_of_day" onkeyup='checkParams()'> <option value="default" selected>...</option> <option value="Утром">Утром</option> <option value="Днём">Днём</option> <option value="Вечером">Вечером</option> <option value="Ночью">Ночью</option> </select> <input type="text" name="time" id="time" class="form-control floating-label" onkeyup='checkParams()'> 

The script works to say the least randomly, JS just started to learn, please at least just point out the errors.

    1 answer 1

    You had the wrong $("#time_of_day").on('change', function() { , it should have been located outside the checkParams() handler checkParams() . Also fixed the condition for if . And it is advisable to use the onchange() method for select'а

     //Обработчик вне функции $("#time_of_day").on('change', function() { if ($(this).val() != 'default') { //Обратите внимание на условие $('#time').attr('disabled', 'disabled'); } else { $('#time').removeAttr('disabled'); } }); function checkParams() { var time = $('#time').val(); if (time.length == 0) { $('#time_of_day').removeAttr('disabled'); } else { $('#time_of_day').attr('disabled', 'disabled'); } } 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select name="time_of_day" id="time_of_day" onchange='checkParams()'> <option value="default" selected>...</option> <option value="Утром">Утром</option> <option value="Днём">Днём</option> <option value="Вечером">Вечером</option> <option value="Ночью">Ночью</option> </select> <input type="text" name="time" id="time" class="form-control floating-label" onkeyup='checkParams()'>