jquery - Why is the value of my input appearing blank? -
i writing script finds value of text input it's typed. whatever reason, in console, value blank.
$('[rel^="livesearch"]').ready(function(){ var fieldname = $(this).attr("name"); $(this).on('keydown', function(){ console.log('a key pressed... value '+$(this).val()); if($(this).length > 3){ $.ajax({ url: $(this).attr("rel") + $(this).val(), datatype: "xml", statuscode: { 404: function(){alert("404 not found!")} } }) .done(function(xml){ $(xml).find('member').each(function(){ var memberid = $(this).attr("id"); var membername = $(this).find('content').text(); suggestionmenu.append('<li onclick="appendvalue(\''+fieldname+'\', \''+memberid+'\');hidemenu(\''+suggestionmenu+'\');">'+membername+'</li>'); suggestionmenu.show(); }); }); } }); });
the message logged in console, know on keydown function called. console shows "a key pressed... value "... ideas?
i'm not sure why using $('[rel^="livesearch"]').ready(
.
if input
dynamically generated, use this,
$(document).on('keydown', '[rel^="livesearch"]', function () { var fieldname = $(this).attr("name"); console.log('a key pressed... value ' + $(this).val()); if ($(this).val().length > 3) { $.ajax({ url: $(this).attr("rel") + $(this).val(), datatype: "xml", statuscode: { 404: function () { alert("404 not found!") } } }) .done(function (xml) { $(xml).find('member').each(function () { var memberid = $(this).attr("id"); var membername = $(this).find('content').text(); suggestionmenu.append('<li onclick="appendvalue(\'' + fieldname + '\', \'' + memberid + '\');hidemenu(\'' + suggestionmenu + '\');">' + membername + '</li>'); suggestionmenu.show(); }); }); } });
it work fine.
Comments
Post a Comment