I just realized that this piece of code works well in Firefox but not in IE 8. I need to automatically populate the list when the user enters at least 8 characters in the input field.
$('#inputField').keyup(function (event) {
var $inputField = $(this);
if ($inputField.val().length >= 8) { popularListBox(); }
});
function populateListBox(){
$.get("Default.aspx?name=test", function(data) {
$('#listBox').children().remove();
var options = data;
$("#listBox").html(data);
});
}
I just realized that this piece of code works well in Firefox but not in IE 8. I need to automatically populate the list when the user enters at least 8 characters in the input field.
$('#inputField').keyup(function (event) {
var $inputField = $(this);
if ($inputField.val().length >= 8) { popularListBox(); }
});
function populateListBox(){
$.get("Default.aspx?name=test", function(data) {
$('#listBox').children().remove();
var options = data;
$("#listBox").html(data);
});
}
Share
Improve this question
edited Jun 10, 2012 at 23:40
pb2q
59.7k19 gold badges150 silver badges152 bronze badges
asked Jun 10, 2012 at 2:48
user385599user385599
251 silver badge8 bronze badges
10
-
I think the problem is in your
popularList()
. Your code does not seem incorrect to me. – Derek 朕會功夫 Commented Jun 10, 2012 at 2:50 - 3 why are you using setTimeout? – Ram Commented Jun 10, 2012 at 2:53
- You can check functionality availability across browsers here quirksmode/dom/events/keys.html – uadnal Commented Jun 10, 2012 at 2:53
- 1 This looks like a good candidate for jQuery UI autoplete... – Rob Commented Jun 10, 2012 at 2:56
- @Derek Still confuse why this does not work in IE.function populateListBox() { $.get("???", function( data ) { $('#listBox').children().remove(); var options = data; $("#listBox").append( options ); $("#listBox").html( data ); }); } – user385599 Commented Jun 10, 2012 at 3:39
1 Answer
Reset to default 5You want to detect the change in input field and then do some actions, right?
I think you may detect the changes instead of keyboard actions only. For example, how about if the user paste from clipboard?
Please try these codes:
$('#inputField').bind('propertychange input paste', function() {
// do poppularListBox()
});
It works for most input field including textarea. Please check jQuery site for more information.
In my experience, .keyup() and .keypress() often get errors in IE. I would like to use .keydown() if possible (case by case)