owenparker
asked on
Small problem with nodstrum.com AJAX autocomplete/sugges function
Been poking around all day 'learning' and finally found an autocomplete function that I can work with. Got it at http://nodstrum.com/2007/09/19/autocompleter/
Got it all installed and it works perfectly, got it re-configured only to find out it didn;t fill in the input when I clicked a choice from the popup list. Switched it back to irf\ginal version and same thing, nada. So my question is, simply what could possibly be wrong with the fill() function? It works on the site demo, so I am assuming it should work on mine :) I can post code, but the only changes I made were to the MySQl server setting, database and table and field names. Never even touched the js file...
Little help? TIA if you can...
Owen
Got it all installed and it works perfectly, got it re-configured only to find out it didn;t fill in the input when I clicked a choice from the popup list. Switched it back to irf\ginal version and same thing, nada. So my question is, simply what could possibly be wrong with the fill() function? It works on the site demo, so I am assuming it should work on mine :) I can post code, but the only changes I made were to the MySQl server setting, database and table and field names. Never even touched the js file...
Little help? TIA if you can...
Owen
ASKER
I actually went back to the original code downloaded and the same issue was present. Thus my quandry... Thanx for the reply, however...
you cannot run the code even at its default?
ASKER
I just re-downloaded original zip and got the demo working. won;t be long now i suspect :)
goodluck, 1 step/change at a time :)
ASKER
ok, got the demo working, changed my table to have the same column name, data type, size, etc as the sample code table so all i changed in the sample code was the actual table name in the select statement. the suggestion list comes up as expected but when i click, the chosen result will not fill the field???!!! Now I am very stumped. ARGH!
did the original unmodified example fill the field properly?
ASKER
ok, finally some success. some of the entries work, some don't. the only oddity i can see with the ones that don't fill would be an apostrophe. How exactly may i get around this?
then you probably need to escape the apostrophe character by putting "\" the escape character before it.
Eg:
\'
Eg:
\'
ASKER
it's definitely the apostrophe. Where exactly would I escape it? I slipped in the code where it is building the suggestion box...
$query = $db->query("SELECT value FROM inventory WHERE value LIKE '%$queryString%'");
if($query) {
// While there are results loop through them - fetching an Object (i like PHP5 btw!).
while ($result = $query ->fetch_object()) {
// Format the results, im using <li> for the list, you can change it.
// The onClick function fills the textbox with the result.
// YOU MUST CHANGE: $result->value to $result->your_colum
echo '<li onClick="fill(\''.$result->value.'\');">'.$result->value.'</li>';
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Timely response, and near-live back and forth. A small problem that caused a lot of trouble solved :)
ASKER
Thanx a mil' nizsmo. This small thing had me really stumped. Very nice to have someone to bounce things off. Your help was very much appreciated, my brother...
no problems at all, glad to be of assistance! :)
It sounds like you haven't changed much. Often a good way is to change only one thing at a time and after the thing you change, try the script and make sure the change doesn't stop the script from working. This way you will know exactly which changes will work fine and which changes you made has caused the problem.
Hope this helps.