On Wed, 19 Oct 2005 16:18:55 -0400, Jesse Erlbaum wrote:
Hi Jesse
> Your Javascript would make an HTTP request on timeout (for example,
> when the user stops typing for a couple seconds). That request
> would be internal, and would get back a line-delimited list of
> options, which would then be displayed via DHTML.
The below is based on JavaScript::RPC::Server::CGI.
I don't use timeout, I send every char back to a Perl module (RPC.pm), which
connects to the db, and then does:
(This Perl is from my Database.pm):
# -----------------------------------------------
sub find_entity_via_keystrokes
{
my($self, $prefix) = @_;
my($sql) = "select entity_id, entity_name from
entity where entity_name_key
like lower('$prefix%') order by entity_name";
my($result) = $$self{'_dbh'} ->
selectcol_arrayref($sql, {Columns => [1,
2]});
$result = [1, '-'] if ($#$result < 0);
join($;, @$result);
} # End of find_entity_via_keystrokes.
# -----------------------------------------------
sub find_position_title_via_keystrokes
{
my($self, $prefix) = @_;
my($sql) = "select position_title_id,
position_title_name from position_title
where position_title_name_key like lower('$prefix%') order by
position_title_name";
my($result) = $$self{'_dbh'} ->
selectcol_arrayref($sql, {Columns => [1,
2]});
$result = [1, '-'] if ($#$result < 0);
join($;, @$result);
} # End of find_position_title_via_keystrokes.
# -----------------------------------------------
For those of you who don't remember the bad old times, this char-by-char
narrowing down of a search is called 'progressive search', although I assume it
has other names too.
The corresponding Javascript is:
function find_position_title(prefix)
{
if (prefix != '')
{
jsrsExecute('/cgi-bin/rpc-server.cgi',
find_position_title_callback,
'find_position_title', prefix);
}
else
{
document.tree.input_edit_person_position_title_id.options.length = 0;
document.tree.input_edit_person_position_title_id.options[0] =
new Option();
document.tree.input_edit_person_position_title_id.options[0].value = 1;
document.tree.input_edit_person_position_title_id.options[0].text = '-';
}
}
function find_position_title_callback(result)
{
var a = result.split(/\x1c/); // Perl's $; is 0x1c in JS.
var count = - 1;
document.tree.input_edit_person_position_title_id.options.length = 0;
var i;
for (i = 0; i < a.length; i++, i++)
{
count++;
document.tree.input_edit_person_position_title_id.options[count] = new
Option();
document.tree.input_edit_person_position_title_id.options[count].value = a[i];
document.tree.input_edit_person_position_title_id.options[count].text = a[i +
1];
}
}
The Perl module that the JS talks to does:
use base qw(JavaScript::RPC::Server::CGI);
and then creates a db object and then delegates to the above Perl subs.
The HTML is then:
<td><input name="position_title_prefix" tabindex="2412" size="5"
onKeyUp="find_position_title(this.value)"></td>
All this would make a good demo, no?
--
Cheers
Ron Savage, [EMAIL PROTECTED] on 20/10/2005
http://savage.net.au/index.html
Let the record show: Microsoft is not an Australian company
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]