FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Autocomplete textfield problem





bukaida
I was reading the article from http://www.brandspankingnew.net/archive/2007/02/ajax_auto_suggest_v2.html
and downloaded the code from there.The options were static in test.php so I have re-written the code
according to my need as--
Code:

<?php
$input = $_REQUEST['input'];
$link=mysql_connect("localhost", "root", "");
mysql_select_db("biblio",$link);
$qr=mysql_query("SELECT b_id,author FROM bibdata WHERE author LIKE '".$input."%'",$link);
while($row=mysql_fetch_array($qr))
{
$aResults[] = array( "id"=>($row['b_id']) ,"value"=>htmlspecialchars($row['author']), "info"=>htmlspecialchars($row['author']) );
}
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
if (isset($_REQUEST['json']))
   {
      header("Content-Type: application/json");   
      echo "{\"results\": [";
      $arr = array();
      for ($i=0;$i<count($arr);$i++)
      {
         $arr[] = "{\"id\": \"".$aResults[$i]['id']."\", \"value\": \"".$aResults[$i]['value']."\", \"info\": \"\"}";
      }
      echo implode(", ", $arr);
      echo "]}";
   }
   else
   {
      header("Content-Type: text/xml");
      echo "";
      for ($i=0;$i<count($arr);$i++)
      {
         echo "".$aResults[$i]['value']."";
      }
      echo "";
   }
?>


and the html file with textbox as

Code:

<html>
<head>
<title>Ajax auto-suggest / auto-complete | BrandSpankingNew</title>


<script type="text/javascript" src="js/bsn.AutoSuggest_2.1.3.js" charset="utf-8" useBSNns = true;></script>

<link rel="stylesheet" href="css/autosuggest_inquisitor.css" type="text/css" media="screen" charset="utf-8" />

<style type="text/css">

   body {
      font-family: Lucida Grande, Arial, sans-serif;
      font-size: 10px;
      text-align: center;
      margin: 0;
      padding: 0;
   }
   
   table
   {
      border: 1px;
      background-color: #999;
      font-size: 10px;
   }
   tr
   {
      vertical-align: top;
   }
   th
   {
      text-align: left;
      background-color: #ccc;
   }
   th,
   td
   {
      padding: 2px;
      font-family: Lucida Grande, Arial, sans-serif;
      font-size: 1.2em;
   }
   td
   {
      background-color: #fff;
   }
   
   a {
      font-weight: bold;
      text-decoration: none;
      color: #f30;
   }
   
   a:hover {
      color: #fff;
      background-color: #f30;
   }
   
   #wrapper {
      width: 600px;
      margin: 10px auto;
      text-align: left;
   }
   
   #content {
      font-size: 1.2em;
      line-height: 1.8em;
   }
   
   #content h1 {
      font-size: 1.6em;
      border-bottom: 1px solid #ccc;
      padding: 5px 0 5px 0;
   }

   #content h2 {
      font-size: 1.2em;
      margin-top: 3em;
   }








   label
   {
      font-weight: bold;
   }








   
</style>


</head>
<body>

<div id="wrapper">
<div id="content">

<div>
<form method="get" action="">
   <small style="float:right">Hidden ID Field: <input type="text" id="testid" value="" style="font-size: 10px; width: 20px;" disabled="disabled" /></small>
   <label for="testinput">Enter the Author name</label>
   <input style="width: 200px" type="text" id="testinput" value="" />
   <input type="submit" value="submit" />
</form>
</div>
<script type="text/javascript">
   var options = {
      script:"test.php?json=true&limit=6&",
      varname:"input",
      json:true,
      shownoresults:false,
      maxresults:6,
      callback: function (obj) { document.getElementById('testid').value = obj.id; }
   };
   var as_json = new bsn.AutoSuggest('testinput', options);
   
   
   var options_xml = {
      script: function (input) { return "test.php?input="+input+"&testid="+document.getElementById('testid').value; },
      varname:"input"
   };
   var as_xml = new bsn.AutoSuggest('testinput_xml', options_xml);
</script>
</body>
</html>


The table has three fields--
b_id(integer, autoincrement) author(text) and book_name.

The objective is to obtain the corresponding id from the database by specifying the author and pass it to the search page to display the record.
When typing the first character I get the following error in IE7
Line:312
char:3
Error:Syntax error
Code:0

Spent two full days behind it without any solution.The code with static value is doing fine.
Please help.
Stubru Freak
Show us the javascript code produced by your php script. And post it on http://pastebin.com/.
bukaida
The php file is called from the html, and the output of them is already given in the second part(html).Do you want the js file?
Stubru Freak
You didn't tell me what file the syntax error is in, as both of the files shown are less than 312 lines, I assume it's in another file.
bukaida
The html file is the main file to be run.Other files are called by it.This html file is producing all the error.If you download the zip file from the link of my first post(only a few KB) and try to run it using database, you will be able to see it.As I am very new to AJAX, so It is almost impossible for me to debug.

PS. perhaps the html file is counting the blank lines also, so it is reaching the line number 300.
BlueVD
Give us a link. Upload the html and php file on a server. That way we can check it out and see exactly where the problem is.
bukaida
I have given the link in my first post.It will be very helpful if someone download the software and implement it with PHP MYSQL. Then please let me know the result if you are successful.
Stubru Freak
bukaida wrote:
I have given the link in my first post.It will be very helpful if someone download the software and implement it with PHP MYSQL. Then please let me know the result if you are successful.


Why should we work for you? If you expect anyone to help for free, you should do the effort of uploading it to a web server.
Related topics
Problem with Subdomains
Strange Fire fox problem
Logout problem (Cookie?)
How to solve this problem? Thanks
I have a problem....Mozilla Firefox
post nuke problem
anyone had this phpBB problem?
phpbb problem....
Transport yourself over the Net
Problem with my password
Pictures problem...
database problem
same problem over here...
751 Useful Windows XP Files
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.