Use the onkeydown event handler to send the value of the form field via AJAX to the server.
It's worth noting that using onkeydown could lead to inaccurate results. If you press and hold a key down, the events will be:
onkeydown, onkeypress, onkeypress, onkeypress, ..., onkeyup
In other words, onkeypress will be repeated. For that reason, onkeyup is a better listener to attach to.
<script type="text/javascript" language="JavaScript">
Don't use the language attribute. It's invalid.
s1 = new String(myForm.myText.value)
Don't use "new" for String values. Always declare variables using the
var keyword. And don't forget the semicolon:
var s1 = myForm.myText.value;
Here's a summary of the logic I would start with if I was doing it:
1. Attach onkeyup event handler/listener to the input field
2. Use cancelTimeout and setTimeout to schedule the AJAX request for some short time in the future. This is so that if someone is typing quickly, you only perform the search when they have stopped long enough for it to make sense to do the search. Start with a 500ms delay, and adjust from there.
3. When the function in the setTimeout is called, send an AJAX request to the server with the value in the input field. The callback method will get the result and populate the value on the page.
Note, you should also make sure that your callback method verifies somehow that the results back from the server are from the most recent AJAX request. Because AJAX is asynchronous, you might send 2 requests and get the responses back in the wrong order.