के बजाय
<body onload=showUser(str="ALL")>
आपको उपयोग करना चाहिए
<body>
<!-- all your html goes here -->
</body>
<script>
showUser();
</script>
जब body onload
ट्रिगर drop_1
और tire_two
नहीं बनाए गए हैं और स्क्रैप सिर्फ एक अपवाद फेंक देगा।
संपादित करें:
पहली बार लोड करते समय या यदि आपका q=ALL
, आपको दूसरा पैरामीटर भेजने की आवश्यकता नहीं है p
. इसलिए बदलें
if (str == "" || str1 == "") {
document.getElementById("txtHint").innerHTML = "";
return;
}
करने के लिए
if (str == "" || (str != "ALL" && str1 == "")) {
document.getElementById("txtHint").innerHTML = "";
return;
}
2 संपादित करें: संशोधित Combobox.php
<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()" style="overflow:scroll;width:100px;">
<option value="ALL" selected='ALL'>ALL</option>
<?php getTierOne(); ?>
</select>
<!-- your other html... -->
</body>
<script>
showUser();
</script>
3 संपादित करें:
यह एक बेतुका अनुमान है और हो सकता है कि आप यही चाहते हों
func.php
में परिवर्तन
if(isset($_GET['func']) && $_GET['func'] == "drop_1") {
drop_1($_GET['drop_var']);
}else{
drop_1(''); // when you call the func.php first time $_GET['drop_var'] is not set so call with blank drop_var
}
function drop_1($drop_var)
{
$mysqli = new mysqli("localhost", "root", "", "app");
$query = "SELECT * FROM app WHERE app_cn='$drop_var' GROUP BY app_plan_no ORDER BY app_plan_no";
if (empty($drop_var)){
//if the drop_var is empty select all records
$query = "SELECT * FROM app GROUP BY app_plan_no ORDER BY app_plan_no";
}
$results = $mysqli->query($query);
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> ';
}