Jump to content

How to use autocomplete script on mulitple fields?


sfraise

Recommended Posts

I need to run this autocomplete script on multiple fields in a form.

I created separate js and php files for each field and it seems to pull the values from the php file ok, when you don't have a match it correctly displays no results, however when you do have a match the suggestion box disappears in the first field. The last field works correctly.

 

I'm assuming there is a var conflict between the script instances here and need to find a way around it.

 

I've tried playing around with if else statements in both the php file and the js file to try and just use one but I can't get anything to work.

 

You can view the script at

www.erecoverydev.com/autocomplete2/js/jquery.tokeninput.js

 

My php file is:

<?
mysql_pconnect("localhost", "username", "password") or die("Could not connect");
mysql_select_db("mydb") or die("Could not select database");
$param = mysql_real_escape_string ($_GET["q"]);

$query = sprintf("SELECT cb_activities FROM jos_comprofiler WHERE cb_activities REGEXP '^$param'");
$arr = array();
$rs = mysql_query($query);

while($obj = mysql_fetch_object($rs))
{
    $arr[] = $obj;
}

echo json_encode($arr);
?>

 

There has to be a simple way to use multiple instances of this.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.