Book List App: Using Auto-Suggest with CodeIgniter

I had a couple fields on the form for adding authors/books to the DB for which I wanted to use an “auto-suggest” feature via JavaScript; one of those things where after you start typing it pops up a list of matching choices from which you can select the one you want. After trying several different scripts that I could not get to work for one reason or another, I ended up using Ajax Auto Suggest v.2.

I did, however, have to change one line of that JavaScript file in order to get it to play nicely with CodeIgniter “friendly” URLs. I just got rid of the bit that set a varname= part of the URL:

	// create ajax request
	if (typeof(this.oP.script) == "function")
		var url = this.oP.script(encodeURIComponent(this.sInp));
		// var url = this.oP.script+this.oP.varname+"="+encodeURIComponent(this.sInp);
		var url = this.oP.script+encodeURIComponent(this.sInp);

Then when activating it within the page (CI view), I simply specified the CI URL to the controller/function with a trailing slash, to which the JS script then appends the value which my CI method will receive as its first (and only) parameter:

<script type='text/javascript'>
// <![CDATA[
	var options = {
	var as_json = new bsn.AutoSuggest('author', options);
// ]]>