hey!
so i found the following script
http://www.dhtmlgoodies.com/index.html?whichScript=ajax-dynamic-list
I figured I could use it and turn it into a stock symbol autocomplete where results come up
as you type letters (like spotlight on mac)
I have it working, kind of.
http://adammesh.com/charts-test.php
The problem I’m having… when I select a stock symbol from the drop down menu, it adds the symbol and the name of the company into the text field. I only need it to add the symbol. The reason for this is because the text field sends a variable to some flash code I have on the page so that it may display the correct stock information within the chart. Here is some code so that you may understand a bit better:
Form:
<form name="form1" method="post" action="charts-test.php">
<td width="66" bgcolor="#000066">
<div class="fieldbox">
<input name="symbol" type="text" id="theName" onkeyup="ajax_showOptions(this,'getCountriesByLetters',event)" value="<?=$_POST['symbol']?>" size="44" maxlength="4" autocomplete="off"/>
<input type="submit" name="Submit" value="Get Chart" /><p class="field_desc"><font color="#FFFFFF">Enter a symbol</font></p>
</div> </td>
<td width="100%" bgcolor="#000066" style="color:#FFFFFF;"><br />
<input type="hidden" name="submitted" value="TRUE"> </td>
</form>
File that gets the stock symbols from the database:
<?
$conn = mysql_connect("","","");
mysql_select_db("",$conn);
if(isset($_GET['getCountriesByLetters']) && isset($_GET['letters'])){
$letters = $_GET['letters'];
$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
$res = mysql_query("select countryName, countryDescription from ajax_countries where countryName like '".$letters."%'") or die(mysql_error());
#echo "1###select ID,countryName,countryDescription from ajax_countries where countryName like '".$letters."%'|";
while($inf = mysql_fetch_array($res)){
echo $inf["ID"]."###".$inf["countryName"]."".$inf["countryDescription"]."|";
}
}
?>
The db only has 3 fields: id, countryName, countryDescription
Also, I was thinking, would it also be possible to bold the search results letter by letter as type them?
And I need it to echo “No results” if nothing matches…
Thanks in advance!
p.s. I left all the variables just as the original script author left them fully intending to clean everything up once i get this working.