pooker Posted June 18, 2008 Share Posted June 18, 2008 Here is the code , what I want it to do, is when a user clicks on an option in the first dropdown menu, it invokes th second dropdown menu to appear. <?php ob_start(); include('config1.php'); mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $list = mysql_query("SELECT value,title FROM $tbl_name"); ?> <select name="manga" onchange=""> <?php while ($row_list = mysql_fetch_assoc($list)) { ?> <option value="<?php echo $row_list['value'] ?>"> <?php echo $row_list['title'] ?></option>; <?php } ?> <select name="chapters" onchange=""> </select> </select> <?php ob_end_flush(); ?> Link to comment https://forums.phpfreaks.com/topic/110706-dropdown-menu-creates-new-dropdown-menu/ Share on other sites More sharing options...
pooker Posted June 18, 2008 Author Share Posted June 18, 2008 Alright remember I am still new, but I tried making a function that is called when an item is selected and it says error on line 22 right where I start the function I created , I think that means I created the function wrong some how? <?php ob_start(); include('config1.php'); mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $list = mysql_query("SELECT value,title,chapters FROM $tbl_name"); ?> <select name="manga" onchange="<?php echo $chapters ?>"> <?php while ($row_list = mysql_fetch_assoc($list)) { ?> <option value="<?php echo $row_list['value'] ?>"> <?php echo $row_list['title'] ?></option>; <?php } ?> </select> <?php $chapters= create_function(?> <select name="chapters" onchange=""> <option value=""><?php echo $row_list['chapters'] ?></options>; </select> <?php ) ;?> <?php ob_end_flush(); ?> Link to comment https://forums.phpfreaks.com/topic/110706-dropdown-menu-creates-new-dropdown-menu/#findComment-567974 Share on other sites More sharing options...
pooker Posted June 18, 2008 Author Share Posted June 18, 2008 recorrected, can an onchange not call a php function? no errors <?php ob_start(); include('config1.php'); mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $list = mysql_query("SELECT value,title,chapters FROM $tbl_name"); ?> <select name="manga" onchange="<?php echo chapters(); ?>"> <?php while ($row_list = mysql_fetch_assoc($list)) { ?> <option value="<?php echo $row_list['value'] ?>"> <?php echo $row_list['title'] ?></option>; <?php } ?> </select> <?php function chapters() {?> <select name="chapters" onchange=""> <option value=""><?php echo $row_list['chapters'] ?></options>; </select> <?php }?> <?php ob_end_flush(); ?> Link to comment https://forums.phpfreaks.com/topic/110706-dropdown-menu-creates-new-dropdown-menu/#findComment-567980 Share on other sites More sharing options...
mmarif4u Posted June 18, 2008 Share Posted June 18, 2008 Mr pooker read the following link and follow it ,hopefully will solve your problem. http://www.plus2net.com/php_tutorial/php_drop_down_list.php Link to comment https://forums.phpfreaks.com/topic/110706-dropdown-menu-creates-new-dropdown-menu/#findComment-567983 Share on other sites More sharing options...
pooker Posted June 18, 2008 Author Share Posted June 18, 2008 Thank you but I am not very understanding of javascript so that article is confusing to me. :'( Link to comment https://forums.phpfreaks.com/topic/110706-dropdown-menu-creates-new-dropdown-menu/#findComment-567994 Share on other sites More sharing options...
mmarif4u Posted June 18, 2008 Share Posted June 18, 2008 For dynamic drop down there are two way, 1- Javascript 2- Ajax that is not confusing,its simple. Let me arrange it for you. $dbservertype='mysql'; $servername='localhost'; // username and password to log onto db server $dbusername=''; $dbpassword=''; // name of database $dbname='tutorial'; //////////////////////////////////////// ////// DONOT EDIT BELOW ///////// /////////////////////////////////////// connecttodb($servername,$dbname,$dbusername,$dbpassword); function connecttodb($servername,$dbname,$dbuser,$dbpassword) { global $link; $link=mysql_connect ("$servername","$dbuser","$dbpassword"); if(!$link){die("Could not connect to MySQL");} mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error()); } //////// End of connecting to database //////// ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>Multiple drop down list box from plus2net</title> <SCRIPT language=JavaScript> function reload(form) { var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='dd.php?cat=' + val ; } </script> </head> <body> <? /* If register_global is off in your server then after reloading of the page to get the value of cat from query string we have to take special care. To read more on register_global visit. http://www.plus2net.com/php_tutorial/register-globals.php */ @$cat=$_GET['cat']; // Use this line or below line if register_global is off //@$cat=$HTTP_GET_VARS['cat']; // Use this line or above line if register_global is off ///////// Getting the data from Mysql table for first list box////////// $quer2=mysql_query("SELECT DISTINCT category,cat_id FROM category order by category"); ///////////// End of query for first list box//////////// /////// for second drop down list we will check if category is selected else we will display all the subcategory///// if(isset($cat) and strlen($cat) > 0){ $quer=mysql_query("SELECT DISTINCT subcategory FROM subcategory where cat_id=$cat order by subcategory"); }else{$quer=mysql_query("SELECT DISTINCT subcategory FROM subcategory order by subcategory"); } ////////// end of query for second subcategory drop down list box /////////////////////////// echo "<form method=post name=f1 action='dd-check.php'>"; /// Add your form processing page address to action in above line. Example action=dd-check.php//// ////////// Starting of first drop downlist ///////// echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>"; while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['cat_id']==@$cat){echo "<option selected value='$noticia2[cat_id]'>$noticia2[category]</option>"."<BR>";} else{echo "<option value='$noticia2[cat_id]'>$noticia2[category]</option>";} } echo "</select>"; ////////////////// This will end the first drop down list /////////// ////////// Starting of second drop downlist ///////// echo "<select name='subcat'><option value=''>Select one</option>"; while($noticia = mysql_fetch_array($quer)) { echo "<option value='$noticia[subcategory]'>$noticia[subcategory]</option>"; } echo "</select>"; ////////////////// This will end the second drop down list /////////// //// Add your other form fields as needed here///// echo "<input type=submit value=Submit>"; echo "</form>"; ?> <center><a href='http://www.plus2net.com'>PHP SQL HTML free tutorials and scripts</a></center> </body> </html> change the variables , code and mysql input for your script. Link to comment https://forums.phpfreaks.com/topic/110706-dropdown-menu-creates-new-dropdown-menu/#findComment-567999 Share on other sites More sharing options...
pooker Posted June 18, 2008 Author Share Posted June 18, 2008 Thank you, first week learning php. I actually found a really cool code to use function changeSeries(to) { if (to == "") return false; document.location = "/" + to + ".php"; } Link to comment https://forums.phpfreaks.com/topic/110706-dropdown-menu-creates-new-dropdown-menu/#findComment-568038 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.