javascript - How do I put id number from select tag to a php link? -
currently, have far, it's not working:
<form> <select name="patientid" id="patientselect"> <?php $qpatient = mysql_query("select idpatients, firstname, mi, lastname, suffix patients order 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 here: http://jsfiddle.net/paulpro/euyzp/
changing dropdown's value changes href of links. wanting change links text well?
also side note, shouldn't wrapping code in $(document).ready(), because want script execute <select>
added dom.
Comments
Post a Comment