Reputation: 95
I am trying to incorporate jQuery autocomplete. It works fine with Firefox 3.6.. However it doesnt work in in Chrome 10, Firefox 9, IE 7-9, Opera, Safari 5. Basically all the new browsers. Using debugging tools, the there is a server side response in the format ["Router","Microsoft Outlook 2007",] across all browsers. However the drop down does not appear,except one browser.
Header Files
<script type="text/javascript" src="js/jquery-1.6.2.js"></script>
<script type="text/javascript" src="js/jquery.ui.core.js"></script>
<script type="text/javascript" src="js/jquery.ui.widget.js"></script>
<script type="text/javascript" src="js/jquery.ui.position.js"></script>
<script type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="js/jquery.ui.autocomplete.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
Javascript Function
$(function() {
$("#datepicker").datepicker();
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}
$("#textbox")
// don't navigate away from the field on tab when selecting an item
.bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$( this ).data( "autocomplete" ).menu.active ) {
event.preventDefault();
}
})
.autocomplete({
source: function( request, response ) {
var url=window.location.protocol+"//"+window.location.host+"/test/generateList";
$.getJSON(url, {
term: extractLast( request.term )
}, response );
},
search: function() {
// custom minLength
var term = extractLast( this.value );
if ( term.length < 2 ) {
return false;
}
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function( event, ui ) {
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// add placeholder to get the comma-and-space at the end
terms.push( "" );
this.value = terms.join( ", " );
return false;
}
});
});
Element
Upvotes: 0
Views: 1251
Reputation: 95
The problem is the response.. ["Router","Microsoft Outlook 2007",]. Please note the extra comma(,) at the end. If response is ["Router","Microsoft Outlook 2007"].. It works.
Upvotes: 1
Reputation: 2052
any JS errors you can see from the browser developer tools.(firebugs for firefox and so on)
Upvotes: 0