Jump to content

Recommended Posts

hey guys im trying to get an autocomplete script working at the moment...although im pretty new to jquery...ive added jquery.js and jquery-ui.js (I think I need both?)

 

here is my code if anyone can give me some pointers please...thank you

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="media/scripts/library/jquery.js"></script>
<script src="media/scripts/library/jquery-ui.js"></script>
<script>
$(document).ready(function()
		{
			function autocomplete(selecor, tags)
			{
			    $( '#' . + selector).autocomplete(
			    {
			    	source: tags
			    });
			}
			
			var availableTags = [ "ActionScript",
			                      "AppleScript",
			                      "Asp"];
			
			autocomplete('query', availableTags);
		});
</script>
<title></title>
</head>
<body>
Search: <input type="text" name="q" id="query" />
</body>
</html>
Link to comment
https://forums.phpfreaks.com/topic/289641-autocomplete/
Share on other sites

First thing, you misspelled selector in the function call here

function autocomplete(selecor, tags)

Also, you may have conflict with function names since you are calling your function autocomplete and the jquery included function is also autocomplete.  You may want to change the name of your function so there is no confusion, especially later when you review the code to fix or change it and you can't understand what's going on yourself.

Link to comment
https://forums.phpfreaks.com/topic/289641-autocomplete/#findComment-1484433
Share on other sites

thank you...eeek spelling mistake...ok well I've change all that but it's still not functioning

$(document).ready(function()
{
	function search_autocomplete(selector, tags)
	{
	    $( '#' . + selector).autocomplete(
	    {
	    	source: tags
	    });
	}
	
	var availableTags = [ "ActionScript",
	                      "AppleScript",
	                      "Asp"];
	
	search_autocomplete('query', availableTags);
});
Link to comment
https://forums.phpfreaks.com/topic/289641-autocomplete/#findComment-1484435
Share on other sites

thank you that works great...now when the list comes down from the input box how would I get to the options to change the format of the list please?

 

also it generates this at the bottom of my page

 

"3 results are available..." which I also would like to get rid of please

Link to comment
https://forums.phpfreaks.com/topic/289641-autocomplete/#findComment-1484438
Share on other sites

Do you mean the way the list looks you want to change?  The easiest way if to use a custom theme that you can generate here http://jqueryui.com/themeroller/ , then you just include the download theme and link it like a normall css file on your page.

 

As for the 3 results thing, you haven't provided any code that would generate such a thing, so no idea there.

Link to comment
https://forums.phpfreaks.com/topic/289641-autocomplete/#findComment-1484441
Share on other sites

helpers are able to be turned off buy using this style :)

.ui-helper-hidden-accessible 
{ 
	display: none 
}

although after solving that one problem I have come across another...my unable to view my source, which might have something to do with the way I have my array?

$(document).ready(function()
{	
	function search_autocomplete(selector, tags, default_value)
	{	
		
		$('#' + selector).focus(function() 
		{
			if($('#' + selector).val() == default_value)
			{
				$('#' + selector).val('');
			}
		});
		
		$('#' + selector).blur(function() 
				{
					if($('#' + selector).val() == '')
					{
						$('#' + selector).val(default_value);
					}
				});
		
	    $('#' + selector).autocomplete(
	    {
	    	source: tags,
	    	timeout: 0,
	    	
	    	create: function () 
	    	{
	            $(this).data('ui-autocomplete')._renderItem = function (ul, item) 
	            { 	
	                return $('<li>')
	                .append('<a>'<br>' + item.product + ' /a>')
	                .appendTo(ul);
	            };
	    	}
	    }); 
	}
	
	var availableTags = [{"product":"XBOX 360", "Type":"Electrics"},
	                     {"product":"XBOX One", "Type":"Electrics"},
	                     {"product":"Nike", "Type":"Clothing & Footwear"}]
	
	search_autocomplete('query', availableTags, 'Search...');
});

what im wanting is to have the products in my array to be the source...thank you

Link to comment
https://forums.phpfreaks.com/topic/289641-autocomplete/#findComment-1484605
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.