我正在尝试将变量从3个下拉菜单传递到另一个页面。第一个下拉列表(课程)从数据库动态加载,并正好传递到另一个页面。但是,其他2个下拉列表,其数据是手动设置的,不会传递到另一页面。
<script>
function showCourse() {
var course = document.getElementById('selectCourse').value;
var year = document.getElementById('selectYear').value;
var semester = document.getElementById('selectSemester').value;
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","generateTT.php?course="+course+"&year="+year+"&semester="+semester,true);
xmlhttp.send(null);
}//showCourse
上面是获取数据并发送到其他页面的脚本
<?php
$db_host = 'localhost'; $db_user = 'root'; $db_pass = 'golftdi105'; $db_name = 'finalproject';
$con = mysqli_connect($db_host,$db_user,$db_pass, $db_name);
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
$sql = "SELECT CourseId, CourseName FROM courses";
$result = mysqli_query($con, $sql) or die("Error: ".mysqli_error($con));
while ($row = mysqli_fetch_array($result))
{
$courses[] = '<option value="'.$row['CourseId'].'">'.$row['CourseName'].'</option>';
}
以上是动态加载的下拉列表
<select class="StyleTxtField" id="selectYear" >
<option value = "">Select Year</option>
<option value = "">1</option>
<option value = "">2</option>
<option value = "">3</option>
</select>
<select class="StyleTxtField" id="selectSemester" >
<option value = "">Select Semester</option>
<option value = "">1</option>
<option value = "">2</option>
</select>
<input type="submit" value= "submit" class="StyleButtonField" onclick="showCourse();" />
以上是硬编码的代码。
$course = mysql_real_escape_string($_GET['course']);
$year = mysql_real_escape_string($_GET['year']);
$semester = mysql_real_escape_string($_GET['semester']);
以上是传递数据的页面上的代码。我已经尝试回显这些变量,但只有COURSE变量响应出来。
感谢您的帮助,尽量提供尽可能多的信息。