This is my text box for which I am autocomplete.
<input type="text" name="state" id="state" placeholder="State" maxlength="25" required onkeypress="return nospecialCharacters(event)"/> $("#state").autocomplete({ source: function(request, response) { var statevalue = $.trim($("#state").val()); if (statevalue) { $.ajax({ url: url + 'eee', dataType: 'jsonp', jsonp: false, timeout: 6000, jsonpCallback: 'jsonCallback', delay: 100, success: function(data) { $("#state").empty(); response(data); } }); } }, minLength: 2, appendTo: "#state_result", select: function (event, ui) { $("#state").val(ui.item.label); $("#city").focus(); return false; }, close: function(event, ui) $(this).data().term = null; });
Everything works fine, but the problem I am facing is that when some choice is made in textinput and trying to make backspace, it does not delete any characters (I assume it makes requests, so it keeps updating the box)
Could you let me know how to resolve this?
This is my function called by the key
function nospecialCharacters(thi, dec) { if (window.event) keycode = window.event.keyCode; else if (e) keycode = e.which; else return true; if (((keycode >= 65) && (keycode <= 90)) || ((keycode >= 48) && (keycode <= 57)) || ((keycode >= 97) && (keycode <= 122)) || keycode == 32 || keycode == 45 || keycode == 47 || keycode == 92) { return true; } else { return false; } }
jquery jquery-autocomplete
Pawan
source share