I am trying to get the value from a drop down menu (list) and use that value to create another drop down menu. I have a database in mysql, in that database is a list of departments and then each department has a list of courses. What I am trying to do is have a drop down list for the departments which I have already created and then use the value the user selected to make a drop down list for the courses.
EDIT: Updated code:
JavaScript dropmysql.js
<!-- start: Container -->
<div class="container">
<!-- start: Contact Form -->
<div class="title">
<h4>Contact Form</h4>
</div>
<!-- start: Contact Form -->
<div id="contact-form">
<form method="post" action="assets/upload.php" enctype="multipart/form-data">
<fieldset>
<div class="clearfix">
<label for="name"><span>Name:</span>
</label>
<div class="input">
<input tabindex="1" size="18" id="name" name="name" type="text" value="">
</div>
</div>
<div class="clearfix">
<label for="email"><span>Email:</span>
</label>
<div class="input">
<input tabindex="2" size="25" id="email" name="email" type="text" value="" class="input-xlarge">
</div>
</div>
<div class="dropdown">
<label for="department"><span>Department:</span>
</label>
<select tabindex="3" type="text" name="Department">
<?php while($dept=m ysqli_fetch_array($result)) { echo "<option value=\" ".$dept['dname']."\ ">".$dept[ 'dname']. "</option>"; } //<option value="volvo">Volvo</option>
?>
</select>
</div>
<div class="dropdown" id="course-container">
<!-- SELECT WILL BE PLACED USING JAVASCRIPT -->
</div>
<div class="actions">
<p>
<label for="file"><span>Select file to upload:</span>
</label>
<input tabindex="8" type="file" name="fileToUpload" id="fileToUpload">
</p>
<p>
<input tabindex="3" type="submit" value="Upload File" name="submit" class="btn btn-succes btn-large">
</p>
</div>
</fieldset>
</form>
</div>
<!-- end: Contact Form -->
</div>
<!-- end: Container -->
<!-- start: Java Script -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="js/jquery-1.8.2.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/flexslider.js"></script>
<script src="js/carousel.js"></script>
<script src="js/dropmysql.js"></script>
<script def src="js/custom.js"></script>
<!-- end: Java Script -->
PHP upload.php
<?php
include ("../config/database.php");
if (isset($_POST) && !empty($_POST)) {
$department = $_POST['department'];
$query = "SELECT * FROM courses WHERE dname = '{$department}'";
while (mysql_fetch_assoc($query)) {
echo '<option value="{$value}>{$name}</option>"'; // Loop through the database again and echo them here
}
}
?>
PHP ddown.php:
<?php
include ("../config/database.php");
if (isset($_POST) && !empty($_POST)) {
$department = $_POST['department'];
$query = "SELECT * FROM courses WHERE dname = '{$department}'";
while (mysql_fetch_assoc($query)) {
echo '<option value="{$value}>{$name}</option>"'; // Loop through the database again and echo them here
}
}
?>
</div>