I try to check input, for value, with and without a string. The string (Path to the file) is immediately loaded via callback or by pressing a button, without entering any characters into the input.

function checkPath() { var val = $('#gamelocation').val(); if ($.trim(vall)) { $('#actionBtn').show(); $('#gameBlock').show(); } else { $('#actionBtn').hide(); $('#gameBlock').hide(); } } 
 <input type="text" id="gamelocation" /> <div class="btn-group" id="actionBlock">...</div> <div class="btn-group" id="gameBlock">...</div> 

Tell me, please, how can I instantly hide the blocks if the input is empty and display if there is a record? (An entry is added to this plan: "D: \ Folder \ Folder \")

  • Do I need to show blocks if there are any characters in the input or just records of the form `D: \ Folder \ Folder`? - Raul Rojas

1 answer 1

If I correctly understood the task, the answer is as follows:

Subscribe to input to input like this:

 $('#gamelocation').keyup(checkPath); 

If you need to track the change in value, then:

 $('#gamelocation').change(checkPath); 

https://jsfiddle.net/csbrjd7q/

 function checkPath() { var val = $('#gamelocation').val(); if ($.trim(val)) { $('#actionBlock').show(); $('#gameBlock').show(); } else { $('#actionBlock').hide(); $('#gameBlock').hide(); } } $('#gamelocation').keyup(checkPath); checkPath(); // check initial value 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" id="gamelocation" /> <div class="btn-group" id="actionBlock"> Action block </div> <div class="btn-group" id="gameBlock"> Game block </div> 

  • Thank you! Exactly what is needed ! - Elizabeth
  • excuse me, one more question, when updating the page, even if the information got into the input, the blocks are still hidden, could not solve itself, forced to turn ( - Elizabeth
  • one
    you need to force a handler, as in the last line of the example code. - Raul Rojas