Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Here i've some code for autocomplete in textbox with the sign of "@" and "$"

<script>
	var users = [
		{username: 'lodev09', fullname: 'Jovanni Lo'},
		{username: 'foo', fullname: 'Foo User'},
		{username: 'bar', fullname: 'Bar User'},
		{username: 'twbs', fullname: 'Twitter Bootstrap'},
		{username: 'john', fullname: 'John Doe'},
		{username: 'jane', fullname: 'Jane Doe'},
	];
	
	var stocks = [
		{username: 'BUMI', fullname: 'Bumi Prosperindo'},
		{username: 'BMRI', fullname: 'Bank Mandiri'},
		{username: 'BBRI', fullname: 'Bank BRI'},
		{username: 'BBCA', fullname: 'Bank BCA'},
		{username: 'DBSA', fullname: 'Bank DBS'},
		{username: 'OPRS', fullname: 'Siloam Hospital'},
	];
	
	$('#example-1').keypress(function(event) {			
		if( event.which == 36 )
		{
			$('#example-1').suggest('$', {
				data: stocks,
				map: function(stock) {
					return {
						value: stock.username,
						text: ''+stock.username+' <small>'+stock.fullname+'</small>'
					}
				},
				filter: {
					casesensitive: false,
					limit: 8
				}
			})
		}
		else
		{
			$('#example-1').suggest('@', {
				data: users,
				map: function(user) {
					return {
						value: user.username,
						text: ''+user.username+' <small>'+user.fullname+'</small>'
					}
				},
				filter: {
					casesensitive: false,
					limit: 8
				}
			})
		}
	});
	
</script>


but i've found, this code that work only for the sign "@" not working with the Sign of "$".

what i want is the "@" and "$" is working together within the textbox.

example is :
"the @alpha is going to kill the @BUMI"

thanks.
Posted
Updated 27-Jul-15 3:48am
v2
Comments
Richard Deeming 27-Jul-15 10:13am    
Have a look at Bootstrap Tag Autocomplete[^] - looks like it supports exactly what you're trying to do.
Andrew Budiman 27-Jul-15 10:18am    
isn't this using a div tag ? not using a <input type="text" ?
Afzaal Ahmad Zeeshan 2-Aug-15 10:32am    
Please reply to their comment in order to notify them of your message.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900