I'm new to this so I have a question regarding dependent drop down menu.

I have two drop down menu first, Leave Type and the second Available Balance.

Below shows the js and form.

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {

$("#parent_cat").change(function() {
$(this).after('<div id="loader"><img src="img/loading.gif" alt="loading subcategory" /></div>');
$.get('loadsubcat.php?parent_cat=' + $(this).val(), function(data) {
    $('#loader').slideUp(200, function() {

$sql = mysql_query("SELECT * FROM leaves WHERE emp_id=$emp_id'");

<form method="get">
<label for="category">Leave Type</label>
<select name="parent_cat" id="parent_cat">
 <option> Select one </option>   
if ($row['leave_al'] == 1)
    echo "<option value='Annual Leave'> Annual Leave </option>";

if ($row['leave_matl'] == 1)
    echo "<option value='Maternity Leave'> Maternity Leave </option>";


<label>Available Balance</label>
<select name="sub_cat" id="sub_cat"></select>



$parent_cat = $_GET['parent_cat'];
$emp_id = $_GET['emp_id'];

$query = mysql_query("SELECT * FROM leaves WHERE emp_id = 'OR9090'");
$row = mysql_fetch_array($query);

if ($parent_cat == 'Annual Leave')
   echo "<option value='$row[id]'>$row[total_annual]</option>";

if ($parent_cat == 'Maternity Leave')
  echo "<option value='$row[id]'>$row[maternity_days]</option>";

Example above, parent_cat is been passed to loadsubcat in order to load the available balance. I would also like to pass $emp_id to loadsubcat so that the sql can read based on $emp_id. Right now, I can only assign the emp_id manually. Please help me thanks!

First of all, mysql_* functions have been depreciated. Please consider using mysqli_* or pdo

Based on your situation, I wish to know if the user is allowed to apply the leave for other user? If not, then it will just simply use the $_SESSION variable when user login.

If yes, the you can change this code $.get('loadsubcat.php?parent_cat=' + $(this).val(), function(data) {) to $.get('loadsubcat.php?parent_cat=' + $(this).val()+'&emp_id='+your_emp_id, function(data) {)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.