php - How to have jQuery detect wether first input is text or not and fire the jQuery if it is text -
i want jquery fire after actual text (not backspace or tab pressed) inputted search bar, not possible search results display database.
function searchq() { var searchtxt = $("input[name='search']").val(); $.post("search.php",{searchval:searchtxt,}, function(output) { $("#output").html(output); }); } here input:
<input id='input' type="text" name="search" placeholder="search here..." onkeydown="searchq();" autocomplete="off">
just add if condition based off of results of trim:
if(searchtxt.trim() != '') { // post trim remove whitespace both ends of string. if tab or space thing in value, result of trim empty string.
as @karl-andré gagnon pointed out in comment, there jquery-specific function can use trim whitespace:
if($.trim(searchtxt) != '') {
Comments
Post a Comment