目前,这是我到目前为止所做的,但它不起作用:
<form>
<select name="patientID" id="patientSelect">
<?php
$qPatient = mysql_query("SELECT idpatients, firstName, mi, lastName, suffix FROM patients ORDER BY lastName ASC");
while($rowPatient = mysql_fetch_array( $qPatient )) {
if(isset($rowPatient['suffix']) && !empty($rowPatient['suffix'])){$suffix = " " . $rowPatient['suffix'];}else{$suffix = NULL;}
if(isset($rowPatient['mi']) && !empty($rowPatient['mi'])){$mi = " " . $rowPatient['mi'] . ".";}else{$mi = NULL;}
echo "<option value=" . $rowPatient['idpatients'] . $rowPatient . ">" . $rowPatient['lastName'] . $suffix . ", " . $rowPatient['firstName'] . $mi . "</option>";
}
?>
</select>
<a id="updatelink" href="">....</a>
<a id="deletelink" href="">....</a>
<script type="text/javascript">
$(document).ready(function(){
$("#patientSelect").change(function(){
$("#updatelink").attr('href',"update.php?id="+$("#patientSelect").val());
$("#deletelink").attr('href',"delete.php?id="+$("#patientSelect").val());
});
});
</script>
</form>
答案 0 :(得分:1)
你知道,它正在发挥作用:http://jsfiddle.net/Deele/A35B8/
答案 1 :(得分:1)
您的代码有效。请在此处查看:http://jsfiddle.net/Paulpro/Euyzp/
更改下拉列表的值会更改链接的href。您是否也想更改链接文本?
另外,请注意,您不应该将该代码包装在$(document).ready()中,因为您希望在<select>
添加到DOM后立即执行该脚本。