surf5502 Posted November 25, 2007 Share Posted November 25, 2007 So I need to create 3 drop downs. each one feeds off the one above it. so the first dropdown is for a department, when you select that I need every class in that department to come up in the next dropdown. when you select a class i need ever professor for that class to appear in the third dropdown. so i had it working for a solid 10 min... now it doesnt work... HTML <script type="text/javascript" src="../../js/upload.js"></script> <form action="" method="post" enctype="multipart/form-data"> <?php if (($_POST['title']!="")&&(!validateForm())) echo "<center><b>Form Invalid</b></center>"; ?> <?php if (isset($error)) echo "<center><b>Error during file upload</b></center>"; ?> <table width="550" align="center" cellpadding="0" cellspacing="0"> <tr><td><b>Department:</b></td><td><select name="dept" onchange="showClass(this.value)"> <option value="">-- Select Deptartment --</option> <?php $query = "SELECT * FROM `categ_dept` ORDER BY `name` ASC"; $result = mysql_query($query); $rows = mysql_num_rows($result); $i = 0; while ($i < $rows){ $name = mysql_result($result, $i, "name"); $id = mysql_result($result, $i, "id"); echo "<option value=\"$id|$name\""; if ($_POST['dept'] == $id) echo " selected"; echo ">$name</option> "; $i++; } ?> </select></td></tr> <tr><td><b>Class:</b><br/><br/></td><td><div id="txtClass"><select name="class" onchange="showProf(this.value)"> <option value="">-- Select Deptartment First --</option> </select></div><br/><br/></td></tr> <tr><td colspan="2" style="border:1px solid #CCCCCC; border-bottom:none; text-align:center; padding-top:10px;"><b><i>If your class is not listed please use this box</i></b></td></tr> <tr><td style="border-left:1px solid #CCCCCC; padding:10px;"><b>Class Name:</b></td><td style="border-right:1px solid #CCCCCC;"><input type="text" name="class_name" value="<?php echo $_POST['class_name']; ?>" /></td></tr> <tr><td style="border-left:1px solid #CCCCCC; padding:10px;"><b>Call Number:</b><br/><i>ex: W3256</i></td><td style="border-right:1px solid #CCCCCC;"><input type="text" name="class_call" value="<?php echo $_POST['class_call']; ?>" /></td></tr> <tr><td style="border-left:1px solid #CCCCCC; padding:10px;"><b>Keywords:</b><br/><i>Seperate by spaces</i></td><td style="border-right:1px solid #CCCCCC;" valign="middle"><input type="text" name="class_keywords" value="<?php echo $_POST['class_keywords']; ?>" /></td></tr> <tr><td style="border:1px solid #CCCCCC; border-top:none; border-right:none; padding:10px;"><b>Description:</b></td><td style="border:1px solid #CCCCCC; border-top:none; border-left:none;"><textarea name="class_des" rows="4"><?php echo $_POST['class_des']; ?></textarea></td></tr> <tr><td><br/><b>Professor:</b><br/><br/></td><td><br/><div id="txtProf"><select name="professor"> <option value="">-- Select Class First --</option> </select></div><br/><br/></td></tr> <tr><td colspan="2" style="border:1px solid #CCCCCC; border-bottom:none; text-align:center; padding-top:10px;"><b><i>If your professor is not listed please use this box</i></b></td></tr> <tr><td style="border:1px solid #CCCCCC; border-top:none; border-right:none; padding:10px;"><b>Professor Name:</b></td><td style="border:1px solid #CCCCCC; border-top:none; border-left:none;"><input type="text" name="prof_name" value="<?php echo $_POST['prof_name']; ?>" /></td></tr> <tr><td colspan="2" align="center" style="padding-top:30px;"><input type="submit" value="Upload" /></td></tr> </table> </form> JAVASCRIPT - upload.js var xmlHttp; var showID = 0; function showClass(str){ xmlHttp=GetXmlHttpObject(); if (xmlHttp==null){ alert ("Browser does not support HTTP Request"); return; } showID = 1; var url="../../includes/getDropdown.php"; url=url+"?q="+str; url=url+"&sid="+showID; xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function showProf(str){ xmlHttp=GetXmlHttpObject(); if (xmlHttp==null){ alert ("Browser does not support HTTP Request"); return; } showID = 2; var url="../../getDropdown.php"; url=url+"?q="+str; url=url+"&sid="+showID; xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function stateChanged(){ if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ if (showID==1){ document.getElementById("txtClass").innerHTML=xmlHttp.responseText; }else{ document.getElementById("txtProf").innerHTML=xmlHttp.responseText; } } } function GetXmlHttpObject(){ var xmlHttp=null; try{ // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType('text/html'); } }catch (e){ //Internet Explorer try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }catch (e){ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } PHP - getDropdown.php <?php @session_start(); $q = $_GET['q']; $sid = $_GET['sid']; include ("config.php"); mysql_connect($hostaddr,$username,$password); @mysql_select_db($database) or die("Error: Database not available. Please try again later."); if ($sid == 1){ // q is a department id // return classes for that department echo "<select name=\"class\" onchange=\"showProf(this.value)\"> "; $dept = explode("|",$q); $query = "SELECT * FROM `categ_class` WHERE `dept_id`='".$dept[0]."' AND `school_id`='".$_SESSION['school']."' ORDER BY `name` ASC"; $result = mysql_query($query); $rows = mysql_num_rows($result); $i = 0; if ($rows == 0){ echo "<option value=\"\">No Classes Listed</option>"; }else{ echo "<option value=\"\">-- Select a Class --</option> "; while ($i < $rows){ $name = mysql_result($result, $i, "name"); $call = mysql_result($result,$i,"call_num"); $id = mysql_result($result, $i, "id"); echo "<option value=\"$id\""; if ($_POST['class'] == $id) echo " selected"; echo ">$name ($call)</option> "; $i++; } } echo "</select>"; }else{ // q is a class id // return professors for that class echo "<select name=\"professor\"> "; $query = "SELECT * FROM `categ_prof` WHERE `class_id`='".mysql_real_escape_string($q)."' ORDER BY `name` ASC"; $result = mysql_query($query); $rows = mysql_num_rows($result); $i = 0; if ($rows == 0){ echo "<option value=\"\">No Professors Listed</option>"; }else{ echo "<option value=\"\">-- Select a Professor --</option> "; while ($i < $rows){ $name = mysql_result($result, $i, "name"); $id = mysql_result($result, $i, "id"); echo "<option value=\"$id\""; if ($_POST['professor'] == $id) echo " selected"; echo ">$name</option> "; $i++; } } echo "</select>"; } ?> Any help is greatly appreciated (quicker the better, gotta finish this thing this week)... Quote Link to comment Share on other sites More sharing options...
surf5502 Posted November 25, 2007 Author Share Posted November 25, 2007 yea i forgot i did a mod_rewrite... new hierarchy errors came into play Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.