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--
and the html file with textbox as
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.
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.
