给你的选择框一个 ID
<select id="selectcompany" name="firma" style="width:200pt">
我不知道这是否可能仅使用 javascript,但这里有一个使用 jQuery 的示例:
addresult.js :
$("select#selectcompany").ready(function(){
$("select#selectcompany").on('change',function(){
clearTimeout(delayTimer);
delayTimer= setTimeout(function(){
$.post("getResult.php", {"selectedValue" : $(this).val()}, function(data){
if(data.length > 0) {
$('#result').empty();
$('#result').show();
$each(data,function(key,value){
$('#result').append('<input id="resultvalue" type="text" value="'+value+'" />');
}
$("#resultvalue").attr("readonly","true");
}
});
}, 500);
});
});
您将需要一个
<div id="result"></div>
或类似的东西,你的结果应该显示在哪里。
在您的 PHP 函数中,您只需要回显您想要显示的数据。jQuery 将接收您的信息并将其保存在可变数据中。
那么这取决于你,你将如何显示它。
希望我能帮助你:) 我不知道这是否有效,没有某种错误,因为未经测试。
编辑:
在您的 php 函数中,您可以创建一个数组并以 JSON 格式返回它:
echo json_encode($myArray);
在你必须这样做的部分:
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="addresult.js"></script>
</head>
在您希望结果出现的正文中,您应该创建
<div id="result"></div>