我有一段JS / PHP代码从数据库中选择,用表的ID做一些事情并在下拉列表中输出数据。
我的JS目前正确地附加myfile.php?cat=X&projectID=Y
并且我正确地抓取变量,但是当我选择第二个下拉列表时它不输出名称,它只将ID附加到标题和变量.. < / p>
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
var val2=form.cat2.options[form.cat2.options.selectedIndex].value;
self.location='add-recharge.php?cat=' + val + '&projectID=' + val2;
}
PHP
<?
@$cat=$_GET['cat'];
if(strlen($cat) > 0 and !is_numeric($cat)){
echo "Data Error";
exit;
}
//MYSQL stuff
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select a client</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['clientID']==@$cat){echo "<option selected value='$noticia2[clientID]'>$noticia2[clientName]</option>"."<BR>";}
else{echo "<option value='$noticia2[clientID]'>$noticia2[clientName]</option>";}
}
echo "</select>";
echo " <span class='req'><img src='/images/essentialInput.png' alt='*' title='*' border='0' /></span>";
echo " <span class='label'>Project</span>" . " ";
echo "<select name='cat2' onchange=\"reload(this.form)\"><option value=''>Select a project</option>";
while($noticia = mysql_fetch_array($quer)) {
echo "<option value='$noticia[projectID]'>$noticia[projectName]</option>";
}
echo "</select>";
echo $intClientID;
//echo "<br /><br /><br /><br />";
?>
如何使用projectName更新它而不是使用“选择项目”重新加载?
答案 0 :(得分:0)
尝试使用:
var val=form.cat.value;
var val2=form.cat2.value;
修改
道歉,我误解了这个问题。您的PHP中需要某种形式的if / else逻辑,类似于Client select上使用的那种逻辑,但依赖于projectID。类似的东西:
if( $_GET['projectID'] == $noticia[projectID] ){
echo "<option selected value='$noticia[projectID]'>$noticia[projectName]</option>";
} else {
echo "<option value='$noticia[projectID]'>$noticia[projectName]</option>";
}