I have two drop-down lists where the second depends on the first drop-down list selection.
I've tested getSalary and getamount and it can fetch the array but cannot be loaded to try.php.
What could have gone wrong? Here are my codes.
try.php:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="jquery-1.11.3.min.js"></script>
<script src="jquery-ui.js"></script>
<script src="script.js"></script>
</head>
<body>
Grade and Increment
<select name="salaryid" id="salaryid" ></select>
<br>
Salary Amount:
<select name="salaryamt" id="salaryamt" ></select>
</body>
</html>
script.js:
$(document).ready(function () {
$.getJSON("getSalary.php", success = function(data) {
var options = "";
for (var i = 0; i < data.length; i++)
{
options += "<options value='" + data[i].toLowerCase() + "'>" + data[i] + "</options>";
}
$("#salaryid").append(options);
$("#salaryid").change();
});
$("#salaryid").change(function(){
$.getJSON("getAmount.php?make=" + $(this).val(), success = function(data) {
var options = "";
for (var i = 0; i < data.length; i++)
{
options += "<options value='" + data[i].toLowerCase() + "'>" + data[i] + "</options>";
}
$("#salaryamt").html("");
$("#salaryamt").append(options);
});
});
});
getSalary.php
<?php
include 'pmis_conn.php';
$qrysal = mysql_query("Select grade_incre from salary_ref where year = '2012'") or die(mysql_error());
$makes = array();
while($row = mysql_fetch_array($qrysal))
{
array_push($makes, $row['grade_incre']);
}
echo json_encode($makes);
?>
getamount.php
<?php
if (isset($_GET["make"])) {
include 'pmis_conn.php';
$make = $_GET["make"];
$qrysal = mysql_query("Select amount, year from salary_ref where grade_incre like '{$make}'") or die(mysql_error());
$amount = array();
while($row = mysql_fetch_array($qrysal))
{
//$amt = $row['amount'] + "-" + $row['year']
array_push($amount, $row['amount']);
}
echo json_encode($amount);
}
?>