我遇到了一些代码问题,因此我要从头开始,但是现在在我的原始代码中无法正常工作的东西在这里工作,我不知道为什么。当我从下拉列表中选择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>
最佳答案
由于name
标记的<select>
属性是year1
,因此此语法
var val=form.year1.options[form.year.options.selectedIndex].value;
应该更改为此
var val=form.year1.options[form.year1.options.selectedIndex].value;