#native_company# #native_desc#
#native_cta#

Remote Scripting with Javascript, IFrames and PHP Page 7

By David Vance
on May 10, 2004

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 
= new getObj('listAsStrng');

    
l.obj.value str;

   

    var list = 
arrayFromString(theString,'|');

    var 
opts '';

  

    for(
i=0< list.lengthi++)

    {

        
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 
= new getObj('searchButton');

    
b.obj.disabled false;

}

?>



1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9