I'm a noob but will gladly take some stick for it if you help me find the answer ;)
I have a list of categories in an array $cat_array. I want to build a select drop-down so that when I select one of the options, a different variable is passed to a function.
This is what I have so far: In the main file (index.php), I call a function:
makechoice($cat_array);
This refers to this function which is in an included file:
function makechoice($cat_array) {
$dbz = new db();
$sim = new simple();
echo '<div class="choose-section">';
echo '<select class="selbox" onchange="categoryAjaxData(\'facebook\',\'/includes/fancount.php\',this.value);">';
foreach($cat_array as $cat) {
echo('<option value="'.$cat[0].'">'.$cat[1].'</option>');
}
echo '</select>';
echo 'Choose a section';
echo '</div>';
echo '<div id="facebook"><div class="facebook-midcut">',showfans($djnames, $djids, $djurl),'</div><div class="l-botcut"></div></div>';
}
In includes/fancount.php, I have basically have lots of different variables that I want to pass through the showfans function.
e.g. $barnames, $barids, $barurl & $restaurantname, $restaurantids, $restauranturl
The showfans function uses these variables to display some data about them.
This is my javascript code:
function categoryAjaxData(div,str,value)
{
var url = str+'?catid='+value;
ajaxData(div,url);
}
function ajaxData(div,str)
{
xmlHttp=GetXmlHttpObject();
document.getElementById(div).innerHTML='<center><img src="images/loader.gif"></center>';
if(xmlHttp==null)
{
alert("Browser does not support HTTP Request")
return
}
var url = str;
xmlHttp.onreadystatechange = function(){ DescriptionstateChanged(div); };
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function DescriptionstateChanged(div)
{
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById(div).innerHTML=xmlHttp.responseText;
}
}
AT THE MOMENT: The content in the current facebook div reloads, I can see the loader - but I'm stuck with how to link the option selected in the select dropdown to changing the variables in the showfans() function.
E.g. I want "Bar" in the dropdown to show:
echo '<div id="facebook"><div class="facebook-midcut">',showfans($barnames, $barids, $barurl),'</div><div class="l-botcut"></div></div>';
I want "Restaurant" in the dropdown to show:
echo '<div id="facebook"><div class="facebook-midcut">',showfans($restaurantnames, $restaurantids, $restauranturl),'</div><div class="l-botcut"></div></div>';
I hope that helps! Thanks in advance :)
UPDATE:
With regards to fancount.php, I have been looking at various different options - but I can't seem to get any of them to work!
I want to pass the value from the dropdown into a logic so that depending on the varlue chosen, certain variables are used by showfans() and the output code looks similar to this for the various combination of variables:
echo '',showfans($restaurantnames, $restaurantids, $restauranturl),'';