I'm having trouble with my body onload function not executing. When I load the page, I want to display all records that are selected in the drop_1 dropdown and equal to ALL. I have a script that sends values q
and p
to getuser.php. The values sent are from the drop_1 and tier_two dropdowns.
Combobox.php
<script type="text/javascript">
$(document).ready(function() {
$('#wait_1').hide();
$('#drop_1').change(function(){
if( $(this).val() == "ALL") {
$("#wait_1").hide();
$("#result_1").hide();
}else{
$('#wait_1').show();
$('#result_1').hide();
$.get("func.php", {
func: "drop_1",
drop_var: $('#drop_1').val()
}, function(response){
$('#result_1').fadeOut();
setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
});
}
return false;
});
});
function finishAjax(id, response) {
$('#wait_1').hide();
$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
</script>
<script> // AJAX Implementation
function showUser() {
str = document.getElementById("drop_1").value;
str1 = document.getElementById("tier_two").value;
if (str == "" || (str != "ALL" && str1 == "")) {
document.getElementById("txtHint").innerHTML = "";
return;
}
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "getuser.php?q=" + str + "&p=" + str1, true);
xmlhttp.send();
}
</script>
<body>
<?php include('func.php'); ?>
<select name="drop_1" id="drop_1" onchange="showUser(this.value)" style="overflow:scroll;width:100px;">
<option value="ALL" selected='ALL'>ALL</option>
<?php getTierOne(); ?>
</select>
<span id="wait_1" style="display: none;">
<img alt="Please Wait" src="ajax-loader.gif" width="15px" height="15px"/>
</span>
<span id="result_1" style="display: none;"></span>
<div id="txtHint"></div>
<script>
showUser();
</script>
func.php
<?php
function getTierOne()
{
$mysqli = new mysqli("localhost", "root", "", "app");
$result = $mysqli->query("SELECT * FROM app GROUP BY app_cn ORDER BY app_cn");
while($row = $result->fetch_assoc())
{
echo '<option value="'.$row['app_cn'].'">'.$row['app_cn'].'</option>';
}
}
if($_GET['func'] == "drop_1" && isset($_GET['func'])) {
drop_1($_GET['drop_var']);
}
function drop_1($drop_var)
{
$mysqli = new mysqli("localhost", "root", "", "app");
$results = $mysqli->query("SELECT * FROM app WHERE app_cn='$drop_var' GROUP BY app_plan_no ORDER BY app_plan_no");
echo '<select name="tier_two" id="tier_two" onchange="showUser()">
<option value=" " disabled="disabled" selected="selected">Choose one</option>';
while($drop_2 = $results->fetch_assoc())
{
if($drop_2['app_plan_no'] != '')
{
echo '<option value="'.$drop_2['app_plan_no'].'">'.$drop_2['app_plan_no'].'</option>';
}
}
echo '</select> ';
}
?>
Getuser.php
$mysqli = new mysqli("localhost", "root", "", "app");
$p = $_GET['p'];
$q = $_GET['q'];
$where = '';
if ( $q != 'ALL') {
$where = " WHERE app_cn='$q' AND app_plan_no='$p' ";
$result1 = $mysqli->query("
SELECT *
FROM app
$where
GROUP BY counter
")or die(mysqli_error());
echo'<table>'
........