寻找一种基于选择来编写 if 语句的方法,该选择将确定xmlhttp.open("GET"
使用的 url。示例 1,2,3 选中"test2.php?q=" + str
, 4 选中"test3.php?q=" + str
, 5 选中"test4.php?q=" + str
<form style="width: 210px">
<select name="bookings" onchange="showbookings(this.value)">
<option value="">Select Booking Types To See:</option>
<option value="1">All Booking</option>
<option value="2">Open Bookings</option>
<option value="3">Closed Bookings</option>
<option value="4">Potential Bookings</option>
<option value="5">Create Bookings</option>
</select>
</form>
<div id="txtBookings"></div>
function showbookings(str) {
if (str === "") {
document.getElementById("txtBookings").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("txtBookings").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET", "test2.php?q=" + str, true);
xmlhttp.send();
}