jquery - Why won't the change event handler work with my code? -


my script below detects when key pressed on text input. problem method detects when keys shift , control , escape pressed. want ajax script execute when text input changed. said, on('keydown', function()) works, on('change', function()) won't when type in field. not sure what's going on here.

$(document).on('change', '[rel^="livesearch"]', function () {              console.log('key pressed');             if($(this).length >= 3){                  var fieldname = $(this).prop("name");                 var searchmenu = $('#livesearch');                  $.ajax({                     url: searchmenu.data('ajax-url')+'/'+$('input[name="'+fieldname+'"]').val(),                     datatype: "xml",                     statuscode: {                         404: function(){alert("404 not found!")}                     }                 })                 .done(function(xml){                     if($(xml).find('member').length > 0){                         $(xml).find('member').each(function(){                             var memberid = $(this).attr("mid");                             var membername = $(this).find('displayname').text();                             searchmenu.html('<li onclick="appendvalue(\''+fieldname+'\', \''+memberid+'\');hidemenu(\''+searchmenu+'\');">'+membername+'</li>');                             searchmenu.show();                         });                     } else {                         searchmenu.html('');                         searchmenu.hide();                     }                 });                               }  }); 

the change event doesn't fire on text input field until leave it.

to detect when real character keys have been typed input, use keypress event instead of keydown.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -