我有MySQL表看上去就像是下拉(选择菜单)的问题
区表
id | region
-------------------
1 | Region1
2 | Region2
...
和学校表
region_id | school
-------------------
1 | schno1
1 | schno5
1 | schno6
2 | scho120
我的页面就像即:首先,页面填充#regions从名为“regions”的数据库表中选择菜单。当用户选择#区域时,js将选定区域的值发送到search.php。 Serverside php脚本在#region(以前选择的菜单)值中搜索名为“schools”的db表,查找所有匹配并回显它们。
现在的问题是,如何隐藏#class和#school选择菜单,并只显示错误消息“在该地区找不到学校”如果找不到匹配项?如何检查search.php没有结果?我是js的新手。如果可能的话,请编辑我的代码。 Thx提前。对不起,我的英语不好
我的JavaScript看起来像http://pastie.org/2444922,并从形式http://pastie.org/2444929的码和最后的search.php http://pastie.org/2444933
UPDATE 我改变了我的js,但没有成功!
$(document).ready(function(){
$("#school").hide();
$("#class").hide();
searchSchool = function(regionSelect){
var selectedRegion = $("select[name*='"+regionSelect.name+"'] option:selected").val();
if (selectedRegion!='0'){
$.ajax({
type: "POST",
url : "core/code/includes/search.php",
data: "®ion_id="+selectedRegion,
success: function(result, status, xResponse){
if (result!=null){
$("#school").show();
$("#class").show();
$("#school").html(result);
}else{
$("#error").html("There is no school found in this region");
$("#school").html('');
$("#school").hide();
}
},
error: function(e){
alert(e);
}
});
}else{
$("#error").html('Please select a region first');
$("#school").html('');
$("#school").hide();
$("#class").hide();
}
}
});
如果您只是想隐藏像你的选择菜单的元素,看看这个:http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/ –
@Knix。首先thx快速回复。不,我想检查发送的查询是否没有结果,然后隐藏这两个依赖菜单并仅显示错误消息。请阅读我的代码。 –
请问您可以通过Skype或其他即时通讯与我聊天吗?我真的需要帮助。我的Skype:tural.teyyuboglu –