我遇到了一些代码问题,所以我从头开始重新开始,但是现在我的原始代码工作的东西在这里工作并不能解决原因。当我从下拉框中选择onchange函数时,它应该触发我的重载函数,没有任何反应。这是我的代码:
<!DOCTYPE html>
<?php
require 'config.php'; // Database connection
//////// End of connecting to database ////////
?>
<html>
<head>
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.year1.options[form.year.options.selectedIndex].value;
self.location='spt.php?year1='+val;
}
</script>
</head>
<body>
<div>
<?Php
@$year1=$_GET['year1'];
@$team1=$_GET['team1'];
$quer1="SELECT DISTINCT year FROM PlayerRegSeason ORDER BY year";
$quer2="SELECT DISTINCT team FROM PlayerRegSeason WHERE year=$year1 ORDER BY team";
$quer3="SELECT fname, lname FROM PlayerRegSeason WHERE year=$year1 and team ='$team1'";
echo "<form method=post name=f1 action ='searchpageresultsdd.php'>";
echo "<select name ='year1' onchange=\"reload(this.form)\"><option value=''>Select Year</option>";
foreach ($dbo->query($quer1) as $row1){
if($row1['year']==@$year1){echo "<option selected value='$row1[year]'>$row1[year]</option>"."<BR>";}
else{echo "<option value='row1[year]'>$row1[year]</option>";}
}
echo "</select>";
?>
</div>
</body>
</html>
答案 0 :(得分:1)
由于name
代码的<select>
属性为year1
,因此语法
var val=form.year1.options[form.year.options.selectedIndex].value;
应更改为此
var val=form.year1.options[form.year1.options.selectedIndex].value;