views:

623

answers:

3
+1  Q: 

yahoo autocomplete

I'm kind of like stuck trying to implement YUI autocomplete textbox. here's the code:

<div id="myAutoComplete"> 
<input id="myInput" type="text" /> 
<div id="myContainer"></div> 
</div>
<script type="text/javascript">
YAHOO.example.BasicRemote = function() {
oDS = new YAHOO.util.XHRDataSource("../User/Home2.aspx");
// Set the responseType
oDS.responseType = YAHOO.util.XHRDataSource.TYPE_TEXT;
// Define the schema of the delimited results
oDS.responseSchema = {
recordDelim: "\n",
fieldDelim: "\t"
};
// Enable caching
oDS.maxCacheEntries = 5;

// Instantiate the AutoComplete
var oAC = new YAHOO.widget.AutoComplete("myInput", "myContainer", oDS);
oDS.generateRequest = function(sQuery) {
return "../User/Home2.aspx?method=" + "SA&Id="+document.getElementById("lbAttributes")[document.getElementById("lbAttributes").selectedIndex].value +"&query="+sQuery;
};
oAC.queryQuestionMark =false;
oAC.allowBrowserAutoComplete=false;
 return {
 oDS: oDS,
 oAC: oAC
 };
}
</script>

I've added all the yahoo javascript references and the style sheets but it never seems to make the ajax call when I change the text in the myInput box and neither does it show anything... I guess I'm missing something imp...

A: 

To be honest, and I know this isn't the most helpful answer... you should look into using jQuery these days as it has totally blown YUI out of the water in terms of ease-of-use, syntax and community following.

Then you could toddle onto http://plugins.jquery.com and find a whole bunch of cool autocomplete plugins with example code etc.

Hope this helps.

adam
Maybe you're right... after trying for some time I gave up and started to view other alternatives, found some pretty cool ones such as mootools autocomplete and others... for the record a good list is maintained at http://webtecker.com/2008/03/10/10-auto-complete-ajax-scripts/. Thanks anyway...
+3  A: 

@Kriss -- Could you post a link to the page where you're having trouble? It's hard to debug XHR autocomplete without seeing what's coming back from the server and seeing the whole context of the page.

@Adam -- jQuery is excellent, yes, but YUI's widgets are all uniformly well-documented and uniformly licensed. That's a compelling source of differentiation today.

Eric Miraglia
Actually it first needs to make that ajax request to bring data from the server. Unfortunately, it doesn't do that and neither does firebug show any errors or that any such request was made... I'm sorry I currently don't have any page uploaded to provide you with a link.
+1  A: 

Yeah, the full source code would help. I would like to see if all of your references to the js includes are there.

mschmidt42