如果我点击提交按钮,系统将显示选项和按钮值。以下是我的编码,请帮忙。我正在尝试使用这么多方法但仍有问题。
<!DOCTYPE html>
<html>
<head>
<script>
function showUser(str) {
if (str=="") {
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("POST","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="users">
<option value="">Select a person:</option>
<option value="1">Person1</option>
<option value="2">Person2</option>
<option value="3">Person3</option>
<option value="4">Person4</option>
</select>
<input name="usersa" type="button" onClick="showUser(this.value)" value="button">
</form>
<br>
<div id="txtHint"><b>Person info will be listed here.</b></div>
</body>
</html>
getuser.php如下。这会将值返回到编码
之上 <?php
$q = $_GET['users'];
echo "test:" .$q;
?>