Rocking
asked on
passing multidimensional array in jquery
hi,
How can i pass multidimensional array in jquery autocomplete.
say var availableTags = [[1,"ActionScript"],[2,Gro ovy]];
How can i pass multidimensional array in jquery autocomplete.
say var availableTags = [[1,"ActionScript"],[2,Gro
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete - Multiple values</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}
$( "#tags" )
// don't navigate away from the field on tab when selecting an item
.bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$( this ).autocomplete( "instance" ).menu.active ) {
event.preventDefault();
}
})
.autocomplete({
minLength: 0,
source: function( request, response ) {
// delegate back to autocomplete, but extract the last term
response( $.ui.autocomplete.filter(
availableTags, extractLast( request.term ) ) );
},
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;
}
});
});
</script>
</head>
<body>
<div class="ui-widget">
<label for="tags">Tag programming languages: </label>
<input id="tags" size="50">
</div>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
text box should display
this.value = ui.item.label;
do you mean you want to display the label only and not the id?
how to get the id of the value from the text box?
to do what?
alert( ui.item.value ); // alert the id
new example : http://jsfiddle.net/2ojLszux/2/
ASKER
http://jsfiddle.net/2ojLszux/2/
It's not working for multiple values
It's not working for multiple values
It's not working for multiple values
I'm not following you
ASKER
What i mean to say when u type A it gives the options,now select Action Script,Output is as per below
1, ActionScript
Working fine
Now the text box has value (1, ActionScript) and i try to type G it should display Groovy it did when i typed A
In this case it is not working
1, ActionScript
Working fine
Now the text box has value (1, ActionScript) and i try to type G it should display Groovy it did when i typed A
In this case it is not working
jquery autocomplete doesn't work like this
your initial question talk about multi array and not putting multi result in a single textbox
your initial question talk about multi array and not putting multi result in a single textbox
ASKER
this.value = ui.item.label;
how to get the id of the value from the text box?