I have a need to fill two input fields using autocomplete. I'd like to pull from of my MySQL table Fname and Lname both in a different column of the table. It seemed to me if I were to concatenate the two fields using CONCAT(Fname, ', ', Lname) as FullName then pass this value back to source of jQuery.
But I don't know what to do from there to split the 'term' value as it returns. Here is what I have. But the return puts both names 'Bill, Smith' for example in both the #Fname and #Lname. I just don't know jQuery well enough yet to figure this out by myself.
On top of that I would like it if the hint would work from either of the two input fields #Fname or #Lname. And break the FullName value into its two parts, filling the appropriate field.
$(document).ready(function () {
$( "#cs1" ).autocomplete({
source: "gethint.php",
autoFocus: true,
focus: function() { return false; }
})
.on( 'autocompleteresponse autocompleteselect', function ( e, ui ) {
var t = $(this),
details = $('#Lname'),
label = ( e.type == 'autocompleteresponse' ? ui.content[0].label : ui.item.label ),
value = ( e.type == 'autocompleteresponse' ? ui.content[0].value : ui.item.value );
t.val( label );
details.val( value );
//alert(label+' '+value);
return false;
});
});