This should be pretty straightforward. I check for the search term, and
call the searchFromJs() funciton if needed. In the searchFromJs() function,
I'm merely building a string containing the database records. The records
are separated by pipes: "|", and the fields are delimited by tildes: "~".
I clean up the string a bit and return it.
The HTML portion of the page is nothing but basic Javascript, so that
when the page is loaded (remember, it's a hidden IFrame), it calls
the handleResponse() Javascript function in it's parent page (search.php).
In the process, it encodes the string. (Not doing this was actually an
undiscovered bug in my application, causing the string to be truncated
in certain cases.)
Let's look at that handleResponse() function now. It looks like this:
<?php
function handleResponse(str)
{
var theString = decodeURIComponent(str);
if(theString == 'No Results' || theString.indexOf('~') == -1)
{
return;
}
var l = new getObj('listAsStrng');
l.obj.value = str;
var list = arrayFromString(theString,'|');
var opts = '';
for(i=0; i < list.length; i++)
{
rec = Array();
rec = list[i].split('~');
opts = opts + '<option value="' + rec[0] +'">' + rec[1] + ' ' + rec[2];
}
var sp = new getObj('spanSelect');
sp.obj.innerHTML = '<select name="names" id="searchSelect">'+opts+'</select>';
var b = new getObj('searchButton');
b.obj.disabled = false;
}