I'm trying to alter this searchscript for use with a selectbox/dropdown menu. Here are the basix:
index.php:
echo '<script src="js/turnsearch.js"></script>';
echo '<select name="search" id="search" onchange="searchUser(this.value)">';
$sql = "SELECT * FROM ".$prefix."_courses";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
if($row['courseid'] == $matchcourse){
echo '<option value"'.$row['courseid'].'" selected>'.$row['coursename'].'</option>';
} else {
echo '<option value"'.$row['courseid'].'">'.$row['coursename'].'</option>';
}
}
echo '</select>';
echo '<div id="searchresult" name="searchresult">';
echo '<select multiple="multiple" size="10" name="turns" style="width: 100%;">';
$sql = "SELECT * FROM ".$prefix."_turns WHERE courseid='$matchcourse'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
echo '<option value="'.$row['turnid'].'">'.$row['turnname'].' '.$row['teecolor'].'</option>';
}
echo '</select> '.$err_turn.'</div>';
turnsearch.js:
var xmlHttp
function searchUser(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="js/turnsearchresult.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("searchresult").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
And turnsearchresult.php
error_reporting(E_ALL);
$q=$_GET["q"];
$con = mysql_connect("localhost","user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$sql="SELECT * FROM turns WHERE courseid LIKE '%$q%' ORDER BY turnname ASC";
$result = mysql_query($sql);
echo '<select multiple="multiple" size="10" name="turn" style="width: 100%;">';
while($row = mysql_fetch_array($result))
{
if($course == $row['courseid']){
echo '<option value="'.$row['turnid'].'" selected>'.$row['turnname'].' '.$row['teecolor'].'</option>';
} else {
echo '<option value="'.$row['turnid'].'">'.$row['turnname'].' '.$row['teecolor'].'</option>';
}
}
echo '</select>';
mysql_close($con);
Now, what I want is to change turns in the multiple select box whenever a course is cahnged in the dropdown menu...
Hope this makes sense, but I can't see the tree's for the forrest!!!
Thanks