PDA

View Full Version : Live Search


Blade_runner
01-18-2007, 07:25 AM
Hi could someone please help me if you have done the sort of thing i would like to do.

Basically i would like to have an event o my textField that it submits data automatically to a methed that runs a search query,the result of the query would be immediatly be displayed below the textField, where you wold be able to click on the results and populate the rest of the form,i am stack with actually getting the textField to to submit automatically and display the results below the textField.

Its more like a live search that will populate the form with data from the database.If anyone has done this please let me know what i need to read on for research.
Thank

mentalhorse
01-18-2007, 12:54 PM
What language are you using?

Blade_runner
01-18-2007, 01:24 PM
Sorry i am using Java, no i dont know why a raven like a writing desk,please let me know

mentalhorse
01-18-2007, 09:27 PM
That is my signature. But here is the answer http://www.straightdope.com/classics/a5_266.html.
For your answer. I'm not really sure. I barely know anything on java. More on c++. Would the javascript code onchange work?

Aradon
01-19-2007, 12:06 AM
Java does have something where you can do onchange, however it may be more important to figure out when the focus is taken off of the textarea / box

Useful Linkage

Java Tutorial (http://java.sun.com/docs/books/tutorial/uiswing/events/focuslistener.html)

Example (http://java.sun.com/docs/books/tutorial/uiswing/events/focuslistener.html)

So when the user loses focus on a textbox or area you can perform your search or have it show up in another place.

mentalhorse
01-19-2007, 12:56 PM
I was talking about javascript actually. Like run something with java through the onchange javascript function. But I don't know what I'm talking about :). I think he wants it so you don't have to click off of the text box. So checking when it loses focus won't work right? Is there a way you could check if the box has changed and then search (see below). And possibly do this every 10 or 5 seconds. Again I don't know much about java just throwing some ideas in the pot :).

if(newBox == oldBox)
{
// search
}

daniel_g
01-20-2007, 03:18 AM
Instead of having a loop running forever, I would create a listener, that will, well, linsten for keystrokes. Everytime a key is depressed, it would start a 3-5 second delay before starting the search. That way it would avoid starting the search before the user is done typing.

I would probably look into the thread class: http://java.sun.com/j2se/1.3/docs/api/java/lang/Thread.html, and the sleep method.
Also the addKeylistener method: http://java.sun.com/j2se/1.3/docs/api/java/awt/Component.html#addKeyListener(java.awt.event.KeyListener). .

EDIT: I don't know ow to do it on javascript.

Blade_runner
01-22-2007, 03:52 PM
Thanks everybody for your help.