0

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) {
    $("#sub_cat").html(data);
    $('#loader').slideUp(200, function() {
        $(this).remove();
    });
}); 
});
});





$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>   
<?php
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>";
}

?>
</select>

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

loadsubcat.php

<?php

$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!

2
Contributors
1
Reply
11
Views
2 Years
Discussion Span
Last Post by lps
0

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) {)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.