I have 2 input. First input with url
type. Second input with file
type. I want to make disable first input when second has value. The same behavior when second input has value. I tried next code but it don't work correctly. Where is my mistake?
$("#src").keyup(function(){
if($('#src').val()){
$("#src_url").toggleClass("disabled-field");
}
});
$("#src_url").keyup(function(){
if($('#src_url').val()){
$("#src").toggleClass("disabled-field");
}
});
.disabled-field{
pointer-events: none;
opacity: 0.5;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="src_url" class="form-control" id="src_url" type="url">
<input name="src" id="src" accept=".pdf, .zip, .rar, .doc, .docx, .rtf" type="file">
Solution:
$("#src_url").on("input", function() {
$("#src").prop("disabled", !!$('#src_url').val());
$("#src").toggleClass("disabled-field", !!$('#src_url').val());
});
$("#src").on("change", function() {
$("#src_url").prop("disabled", !!$('#src').val());
$("#src_url").toggleClass("disabled-field", !!$('#src').val());
});