I have a problem with JQuery 1.3.0 mobile Autocomplete, because I don't know how to select a list item and add the selection into a different DIV or hidden input field! Here is my code:
$( document ).on( "pageinit", "#main", function()
{
$( "#addimageword" ).on( "listviewbeforefilter", function ( e, data )
{
var $ul = $( this ),
$input = $( data.input ),
value = $input.val(),
html = "";
$ul.html( "" );
if ( value && value.length > 2 ) {
$ul.html( "<li><div class='ui-loader'><span class='ui-icon ui-icon-loading'></span></div></li>" );
$ul.listview( "refresh" );
$.ajax({
type : 'GET',
url: "./inc/search2.php",
dataType: "json",
data: {
q: $input.val()
}
})
.then( function ( response ) {
$.each( response, function ( i, val ) {
var substr = val.split('_');
var idword = substr[0];
var your = substr[1];
var lblyour = substr[2];
var learn = substr[3];
var lbllearn = substr[4];
var lblyourlang = substr[6];
var lbllearnlang = substr[7];
html += "<li><a href='#'>" +lblyour+": "+your+" - "+lbllearn+": "+learn+ "</a></li>";
});
$ul.html( html );
$ul.listview("refresh");
$ul.trigger("updatelayout");
});
}
});
$('#addimageword li a').click(function(){
var listItemText = $(this).text;
$('#result').text(listItemText);
$('#addimageword').children('li').hide();
$('#addimageword').bind(function(){
$.mobile.listview.prototype.options.filterPlaceholder = listItemText;
});
e.preventDefault();
})
<ul id="addimageword"
data-role="listview"
data-inset="true"
data-filter="true"
data-filter-placeholder="Type in your word" data-filter-theme="d">
</ul>
<div id="result">
</div>
Does anyone know how it works?
Thank's in advance...