How do I put id number from select tag to a php link?
<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>
You code works. See it here: http://jsfiddle.net/Paulpro/Euyzp/
Changing the dropdown's value changes the href of the links. Are you wanting to change the links text as well?
Also just a side note, you shouldn't be wrapping that code in a $(document).ready(), because you want that script to execute as soon as the <select>
is added to the DOM.
You see, it's working: http://jsfiddle.net/Deele/A35B8/
精彩评论