File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Need help with Auto Complete Script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Need help with Auto Complete Script" Watch "Need help with Auto Complete Script" New topic
Author

Need help with Auto Complete Script

Sandy Joshi
Greenhorn

Joined: Jan 13, 2010
Posts: 4
Hi, recently my clients have asked me to change all the text input types to the auto complete suggestion boxes(Thanks to google's Auto Complete...)
I am good at server side programming but dont know how to make this work. If any one can suggest me some good script or tutorial , it will be really helpful.

Thanks in advance.


Regards,
Javagenious
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

Please take the time to choose the correct forum for your posts. This forum is for questions on JSP. For more information, please read this.

This post has been moved to a more appropriate forum.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
auto complete is pretty easy actually, I believe <input type="text"/> has an event called onKeyUp, so you can get the text in the textbox every time they type...

so if they were typing 'Nike'

when they type the 'N' query your shoes table for 'Like "N%" '.

results for example:

New Balance
Nike

and then when they type 'Ni' query your shoes table for ' Like "Ni%" '.

results:

Nike

To do this you'll probably need to use ajax, because refreshing the page would look silly.

Justin


You down with OOP? Yeah you know me!
Sandy Joshi
Greenhorn

Joined: Jan 13, 2010
Posts: 4
HI,
Thanks for the response. Can you give me any Hint how can i handle that in Ajax. I mean how can i send the string which i capture on keyup and prepare an Ajax request for the same.

Thanks
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802


the code above, just put into a file and save as AJAXLib.js

In the <head></head> of your html file just put:

<script type = "text/javascript" src = "directory/AJAXLib.js"></script>

now in a function that you call on onKeyUp, we'll call it autoComplete(this.value).
So the tag would look like <input type="Text" onclick="autoComplete(this.value)" />

and...


The reason you have to make a callBackFunction is because when you make an ajax request, the response doesn't happen right away so you have to make a callbackfunction to handle the event when the response is ready to be dealt with.

Justin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help with Auto Complete Script