从下拉选择标记获取id以进入链接 [英] get id from drop-down select tag to put into link
问题描述
我为患者提供了一个下拉选择标记:
I have a drop-down select tag for Patients:
<select>
<?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>
这会从下拉列表中生成患者列表。
如何根据我的下拉列表中的选项获取patientID以放入我的链接?
This generates a list of patients from the drop-down. How do I get the patientID based on the selection from my drop-down to put to my link?
ex:< a href =update.php?patientID = $ idpatients>更新< / a>
其中$ idpatients =来自的患者ID下拉列表选择标记。
where $idpatients = the patient ID from the drop-down list select tag.
此外,我需要有3个不同的链接:1。)update.php 2.)chart.php和3.)报告.php
Also, I need to have 3 different links: 1.) update.php 2.) chart.php and 3.) report.php
推荐答案
将此表单方法设置为GET。提交后,select字段的值将显示为get变量。因此,请为您的选择添加名称:
Set this form method to GET. After submiting, value of select field will be shown as get variable. So, add name to your select:
<select name="parientId">
对您的表单采取适当的行动:
And proper action to your form:
<form action="update.php" method="GET">
当然还有提交按钮。
这是静态方式,形式为。如果你确定你想要链接,而不是提交按钮,你可以用jQuery来做:
This is "static way" with form". If you are sure that you want to have link, not submit button, you can do it with jQuery:
$("#go").click(function(){ $("#idOfYourForm").submit(); }
...
<a href="" id="go">Go !</a>
或者抓住<$ c你的< select ...>
并设置<$ c> $ c> .change()(抱歉,不是选择()) 。$ C> $( #去)ATTR( 'HREF', 'update.php patientId =?' + $( #yourSelectId)VAL());
Or catch .change()
(sorry, not select()) on your <select...>
and set $("#go").attr('href','update.php?patientId='+$("#yourSelectId").val());
PS
从SQL中获取您需要的字段,而不是*
P.S. Get from SQL only fields you need, not *
更新
<form...>
<select name="patientId" id="patientSelect">
...
</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="+$("#parientSelect").val());
$("#deletelink").attr('href',"delete.php?id="+$("#parientSelect").val());
}
});
</script>
类似的东西,写得快,没有检查/测试
Something like that, written fast, not checked/tested
这篇关于从下拉选择标记获取id以进入链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!