Jquery autocomplete not working in ie
works fine in firefox and chrome, but still gives an error:
"name is null or not an object
I posted a line not showing in IE in bold.
$("#toemail").autocomplete(emails, {
minChars: 0,
width: 310,
matchContains: true,
autoFill: false,
formatItem: function(row, i, max) {
return i + "/" + max + ": \"" + row.name + "\" [" + row.to + "]";
},
formatMatch: function(row, i, max) {
**return row.name + " " + row.to;**
},
formatResult: function(row) {
return row.to;
}
});
EDIT: I figured it out ... answered below.
source to share
for me, removing the trailing slash in the JSON and these other suggestions didn't work. This is what I did:
Changed:
$(":text, textarea").result(findValueCallback).next().click(function() {
$(this).prev().search();
});
To:
$("#suggest1").result(findValueCallback).next().click(function() {
$(this).prev().search();
});
This has been fixed. #suggest1
is the id of my text input.
source to share
What is the error message? Have you used the stuido / script debugger / ie8 rendering tools to actually go to js and parse strings and max objects to see what they are?
Add a debugger statement as follows and it will be broken into the debugger before the error occurs.
formatMatch: function(row, i, max) {
debugger;
return row.name + " " + row.to;
},
source to share
For some reason IE calls the formatItem function on page load. the same happens with formatMatch and formatResult if you provide custom functions for them. the problem is when IE calls these functions, it doesn't provide any parameters and throws an error.
I fixed this by modifying the plugin script itself, adding tests for the existence of the value before trying to use it. I changed the default formatItem function from
formatItem:function(row){return row[0];}
to
formatItem:function(row){if (row) return row[0]; else return "";}
and by changing the populate () function, I changed
if(value===false)continue;
to
if(!value || value===false)continue;
Also, if you provide your own functions for formatItem, formatMatch or formatResult, be sure to check for the string parameter, e.g .:
formatItem: function( row, i, max ) {
if (row)
return row.name + " (" + row.id + ")";
}
source to share
I know this is an old post, but I had the same problem and wanted to add my "solution" even though I don't feel like it is good.
I used JQuery 1.4.2 to execute an ajax request to display some xml in the autocomplete dropdown but I kept getting this error in IE:
'location.protocol' is null or not an object
I looked online and several sources recommended going back to 1.3.2, which I did, and a few questions I had with ajax calls. I'm not sure what to do with this problem and I don't feel satisfied with the solution, but it did work.
source to share