<?php


require "../config/koneksi.php"; // database connection details 
echo "

function fillCategory(){ 
 // this function is used to fill the category list on load

";

$q1=mysql_query("SELECT * FROM categories");
echo mysql_error();
echo "<Option value='1'>Select Level</option>;";
while($nt1=mysql_fetch_array($q1)){
echo "addOption(document.drop_list.Category, '$nt1[pk]', '$nt1[category]');";
}// end of while
?>
} // end of JS function

function SelectSubCat(){
// ON or after selection of category this function will work

removeAllOptions(document.drop_list.SubCat);
addOption(document.drop_list.SubCat, "", "SubCat", "");

// Collect all element of subcategory for various cat_id 

<?php
// let us collect all cat_id and then collect all subcategory for each cat_id
$q2=mysql_query("SELECT * from menu WHERE menu_parent ='0' AND menu_status='1'");
// In the above query you can collect cat_id from category table also. 
while($nt2=mysql_fetch_array($q2)){
//echo "$nt2[menu_parent] marvin";
echo "if(document.drop_list.Category.value == '$nt2[menu_id]'){";
$q3=mysql_query("SELECT * from main_themes where main_menu_id='$nt2[menu_id]'");
while($nt3=mysql_fetch_array($q3)){
echo "addOption(document.drop_list.SubCat,'$nt3[main_id]', '$nt3[main_title]');";


} // end of while loop
echo "}"; // end of JS if condition

}
?>
}

function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}


function addOption(selectbox, value, text )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;

	selectbox.options.add(optn);
}
