cleary1981 Posted June 24, 2008 Share Posted June 24, 2008 Hi, I am trying to use php to populate 2 dropdown boxes both from a mysql db. Heres my main html code. <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>(Type a title for your page here)</title> <script language="javascript" src="list.php"></script> </head> <body> <FORM name="drop_list" action="" method="POST" > <SELECT NAME="Category" onChange="SelectSubCat();" > <Option value="">Category</option> </SELECT> <SELECT id="SubCat" NAME="SubCat"> <Option value="">SubCat</option> </SELECT> </form> </body> </html> and heres my php (list.php) <?php require "config.php"; // database connection details echo " function fillCategory(){ // this function is used to fill the category list on load "; $q1=mysql_query("select * from category"); echo mysql_error(); while($nt1=mysql_fetch_array($q1)){ echo "addOption(document.drop_list.Category, '$nt1[cat_id]', '$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 <? // let us collect all cat_id and then collect all subcategory for each cat_id $q2=mysql_query("select distinct(cat_id) from subcategory"); // In the above query you can collect cat_id from category table also. while($nt2=mysql_fetch_array($q2)){ //echo "$nt2[cat_id]"; echo "if(document.drop_list.Category.value == '$nt2[cat_id]'){"; $q3=mysql_query("select subcategory from subcategory where cat_id='$nt2[cat_id]'"); while($nt3=mysql_fetch_array($q3)){ echo "addOption(document.drop_list.SubCat,'$nt3[subcategory]', '$nt3[subcategory]');"; } // 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); } config is just the connection to my db. Im getting a syntax error but havnt a clue why. Link to comment https://forums.phpfreaks.com/topic/111654-solved-stupid-error/ Share on other sites More sharing options...
waynew Posted June 24, 2008 Share Posted June 24, 2008 Well, you should really use <?php instead of <? Link to comment https://forums.phpfreaks.com/topic/111654-solved-stupid-error/#findComment-573123 Share on other sites More sharing options...
waynew Posted June 24, 2008 Share Posted June 24, 2008 What's the error? Link to comment https://forums.phpfreaks.com/topic/111654-solved-stupid-error/#findComment-573126 Share on other sites More sharing options...
cleary1981 Posted June 24, 2008 Author Share Posted June 24, 2008 you wouldnt believe. <?php did the trick. :D Link to comment https://forums.phpfreaks.com/topic/111654-solved-stupid-error/#findComment-573259 Share on other sites More sharing options...
Jabop Posted June 24, 2008 Share Posted June 24, 2008 Well, you should really use <?php instead of <? He didn't even post the error, why would you tell him to use long tags? you wouldnt believe. <?php did the trick. :D Did you not have short tags enabled? Hard to tell what it was without your error message. Link to comment https://forums.phpfreaks.com/topic/111654-solved-stupid-error/#findComment-573263 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.