h1

Using autocomplete and Scriptaculous

June 27, 2007

Using this fine page as a reference (http://metapundit.net/sections/blog/ajax_autocomplete_with_scriptaculous), I finally got the autocomplete function working as I wanted.
I wanted to show a venue with some extra info in brackets and when it was selected, to update a hidden input with the id of the venue from the database.

The secret to this was realising that even though I was passing the id of the link tag, it was numberical which is not allowed. So following metapundit’s advice, I added auto_ to the front of the id value. This was then stripped off with javascript and the number put into the hidden input.

Also, a nice thing about the scriptaculous autocomplete is that if you want to show extra info but not have it passed to the page, enclose it in

5 comments

  1. hi! I also use autocomplete with cakephp and I got some code like this:

    form( 'orders/jobType', 'POST', array( 'update' => 'job_type_panel')); ?>
    Service: autoComplete('JobType/title', null, Array( 'id'=>'job_type_autocomplete' ))?>
    submit( "OK" )?>
    

    So I want a user to begin to write a service and the autocomplete would finish it. And it does, but I also want user to get submission results without reloading in a DIV with ID = “job_type_panel” which on the same page with the form.. And now my code does this: after pressing SUBMIT it calls AUTOCOMPLETE, not the “orders/jobType” action and data that appears in “job_type_panel” is the autocomplete results, like and so on.. How can I get autocomplete and update functionality in one ajax form?


  2. oops, stripped of ul and li tags after “results, like”


  3. Hey, sorry for not replying sooner, I was away on holidays.

    Have you checked the source of the page to see what action is being called when the form is submitted? Maybe it is calling the autocomplete again?

    If you can post up the full code or at least re format the code that you have posted here, maybe I can help a bit more.

    Mike.


  4. One problem i had with this autocomplete was that it wasn’t smart enough… ie… if my search term was missing a word, it couldn’t find what i was looking for.

    For example, in a db of cameras if I was looking for a “Camera PowerShot sd800 Digital Elph”
    but only remember the model number, not the full name …so i’d type in “Canon SD800″…and itd give me nothing
    It wasn’t until i typed in “Canon PowerShot SD…” that it found something. I needed it to ignore that I had forgotten PowerShot

    I found a real simple solution – which I describe in detail here – http://www.susanbuck.net/sb/words/index.asp?permanent=yes&permKey=163


  5. It is interested in is present just enoughly. Thank.



Leave a Comment