There is an input type="text" and a button . It is necessary to make a check: if more than one character is entered in input type="text" , the button is active, if less than one, then the button is inactive.

 <input type="text" id="text1"> <button id="btn"></button> 
  • @NickVolynkin, the best solution, how can a moderator call for such cases? Only anxiety set? - user207618
  • @Other in chat said - see? - Nick Volynkin

2 answers 2

For example:

 $('#text1').on('keyup',function(){ var $this = $(this), val = $this.val(); if(val.length >= 1){ $('#btn').show(100); }else { $('#btn').hide(100); } }); 
 #btn { display: none; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> Попробуйте ввести в input что-нибудь. <br/> <input type="text" id="text1"> <button id="btn">button</button> 

  • 2
    @Other is nothing wrong with that. Libraries were made to simplify the work - so there is nothing terrible. And this answer fully answers the question. - alexoander
  • @alexoander, there is no bad, although the whirlists, adherents of jQuery worship, got it, but there are no library tags in the tags, which means you need a vanilla. - user207618

 function ctrlButton() { btn.disabled = this.value.trim().length === 0; } text1.addEventListener('input', ctrlButton, false); ctrlButton.call(text1); 
 <input type="text" id="text1"> <button id="btn">Button</button> 

By the way, you can do without JS

 #text1:invalid + #btn { pointer-events: none; /* для IE < 11 -- display: none; */ } 
 <input type="text" id="text1" pattern=".{1,}" required> <button id="btn">Button</button> 

  • Unfortunately, this code is not suitable for my case. Is it possible to make it so that if was entered "in the input field one or more characters"? - A.Hall
  • @ A.Hall, there it is written. - user207618