This code also includes a Javascript function called “buildQueryString” to,
obviously, build a query string, but since I only needed to pass a single
search term I omitted that function, and changed this line:
obviously, build a query string, but since I only needed to pass a single
search term I omitted that function, and changed this line:
var URL = ‘server.html’ + buildQueryString(theFormName);
…to this line:
var URL = ‘./server.php?s=’+term;
I also added the “term” parameter to the
callToServer()
function.
Now, each time a user makes a keystroke in the “nameSearch” textbox, the
doSearch()
Javascript function is called. That function looks like this:
<?php
function doSearch(theForm)
{
var searchTerm = theForm.elements['nameSearch'].value;
if(searchTerm.length < 2)
{
return;
}
var s="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ -.";
if(s.indexOf(searchTerm.charAt(searchTerm.length-1)) == -1)
{
return;
}
callToServer(searchTerm);
}
?>