Javascript 如何发送php选择框值?
如附图所示,将输出以下代码。 在test16中选择Select框的值,然后按“test19”按钮,这是要修改的Select框的值。 我想知道如何在php中传递选择框的值,以及如何接收传递的值Javascript 如何发送php选择框值?,javascript,php,html,Javascript,Php,Html,如附图所示,将输出以下代码。 在test16中选择Select框的值,然后按“test19”按钮,这是要修改的Select框的值。 我想知道如何在php中传递选择框的值,以及如何接收传递的值 <?php if($result = mysqli_query($link, $sql)){ $test = 'test'; if(mysqli_num_rows($result) > 0){
<?php
if($result = mysqli_query($link, $sql)){
$test = 'test';
if(mysqli_num_rows($result) > 0){
echo "<table id='datatable1' class = table style = 'width: 100%; background-color:#dee2e6'>";
echo "<thead >";
echo "<tr>";
echo "<th>No</th>";
echo "<th>test1</th>";
echo "<th>test2</th>";
echo "<th>test3</th>";
echo "<th>test4</th>";
echo "<th>test5</th>";
echo "<th>test6</th>";
echo "<th>test7</th>";
echo "<th>test8</th>";
echo "<th>test9</th>";
echo "<th>test10</th>";
echo "<th>test11</th>";
echo "<th>test12</th>";
echo "<th>test13</th>";
echo "<th>test14</th>";
echo "<th>test15</th>";
echo "<th>test16</th>";
echo "<th>test17</th>";
echo "<th>test18</th>";
echo "<th>test19</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['chart_num'] . "</td>";
echo "<td>" . $row['chart_name'] . "</td>";
echo "<td>" . $row['visit'] . "</td>";
echo "<td>" . number_format($row['total_medical_bills']) . "</td>";
echo "<td>" . number_format($row['total_amount']) . "</td>";
echo "<td>" . number_format($row['amount_asked']) . "</td>";
echo "<td style = 'font-weight: bold'>" . number_format($row['medical_bills_payment']) . "</td>";
echo "<td style = 'font-weight: bold'>" . number_format($row['personal_liability_amount']) . "</td>";
echo "<td style = 'font-weight: bold'>" . number_format($row['non_payment']) . "</td>";
echo "<td>" . $row['insurance_division'] . "</td>";
echo "<td>" . $row['division'] . "</td>";
echo "<td>" . number_format($row['cash_amount_received']) . "</td>";
echo "<td>" . number_format($row['card_amount_received']) . "</td>";
echo "<td style = 'font-weight: bold'>" . number_format($row['treatment_fees_difference']) . "</td>";
echo "<td>" . $row['treatment_fees_check_division'] . "</td>";
echo "<td><select name='". $test ."'>";
echo "<option value='". $test ."'>First</option>";
echo "<option value='". $test ."'>Second</option>";
echo "<option value='". $test ."'>Third</option>";
echo "</select></td>";
echo "<td>" . $row['treatment_fees_check'] . "</td>";
echo "<td>" . $row['treatment_fees_check_modify'] . "</td>";
echo "<td>";
if($row['medical_bills_payment'] == $row['personal_liability_amount'] + $row['non_payment']){
echo "수정불가";
}
else{
echo "<a href='treatment_fees_check_update.php?id=". $row['id'] ." title='수정' data-toggle='tooltip'><span class='icon ion-edit'></span></a>";
}
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
mysqli_free_result($result);
}
}
else{
echo "ERROR: Could not able to execute $sql2. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
您需要的原则是为下拉列表中的每一个选项指定一个id,这样您就可以发送特定值的id,与数据库中的相同id进行比较(如果存在),然后您将在数据库中有一列包含需要修改的值,但是首先在选择框中为每个选项添加正确的id。因为您可以有很多选择框,您需要给它们一个id,以便我们可以引用相应的字段。让我们添加/更改您的代码,如下所示:
$rowCount=0;
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
...
echo "<td><select id='MySelect".$rowCount."' name='". $test ."'>";
echo "<option value='". $test ."'>First</option>";
echo "<option value='". $test ."'>Second</option>";
echo "<option value='". $test ."'>Third</option>";
echo "</select></td>";
...
echo "<td>";
if($row['medical_bills_payment'] == $row['personal_liability_amount'] + $row['non_payment']){
echo "수정불가";
}
else{
echo '<a href="javascript:GetMySelectValue(\'MySelect'.$rowCount.'\','.$row['id'].')" title="수정" data-toggle="tooltip"><span class="icon ion-edit"></span></a>';
}
echo "</td>";
$rowCount++;
希望它能帮助您。您需要添加一些javascript代码。有几种方法可以做到这一点。1.在javascript代码中,您可以构建url,如处理费检查更新。php?id=xxx&field16=yyy。2.您可以使用表单提交。要做到这一点,你可以用标签包装一张桌子。详细解释请使用@Sandro Benevides的第一个答案。如果select标记的ID和“javascript:GetMySelectValue(xxxx,uuu)”中的ID字符串相同,他会写正确的代码;在关闭之前,同时阻塞。很抱歉我刚刚编辑了答案。
<script>
function GetMySelectValue(select,objId){
document.location.href= "yoursite.com/treatment_fees_check_update.php?id="+objId+"&myselect="+document.getElementById(select).value;
}
</script>
$rowid=$_GET['id'];
$myselect=$_GET['myselect'];