【发布时间】:2020-09-14 21:43:05
【问题描述】:
我正在开发一个应用程序/表单,该应用程序/表单通过带有单选按钮的 foreach 循环从数据库中填充了一个表,一个代表是,一个代表否和一个下拉菜单。 I need it so that when the Yes radio button is selected, the dd is disabled, and when no is selected, it is enabled.我有它的工作,但它只适用于顶行,我无法预先选择所有 Yes 单选按钮。所以简而言之,我不知道如何预先选择所有 yes rd btns,这反过来又会禁用 dd。任何帮助都会很棒。谢谢。
<?php
//Foreach loop iterates through each column of $getallrows function
foreach($allRows as $rowID => $rowInfo){ ?>
<tr>
<td><?php echo $rowInfo['fpID'];?></td>
<td><?php echo $rowInfo['shortTitle'];?></td>
<td><?php echo $rowInfo['PI'];?></td>
<td><?php echo $rowInfo['Department'];?></td>
<td><?php echo $rowInfo['Division'];?></td>
<td><?php echo $rowInfo['sponsorName'];?></td>
<td><?php echo $rowInfo['Date_Project_Start']->format('Y-m-d');?></td>
<td><?php echo $rowInfo['Date_Project_End']->format('Y-m-d');?></td>
<td><?php echo $rowInfo['fundingType'];?></td>
//Radio buttons
<td>Yes<input type="radio" name="rdGrant" value="Yes" id="rdYes" onclick="disable()" checked="checked"/><br />
No<input type="radio" name="rdGrant" value="No" id="rdNo" onclick="enable()"/></td>
<form action="classes/functions.class.php" method="POST">
<input type="hidden" name="id" value="<?php echo $fpID; ?>"/>
<td>
//Drop down
<div class="dropdown">
<button class="btn btn-secondary btn-sm dropdown-toggle" type="button" name="ddgrantGroup" id="ddgrantType" data-toggle="dropdown">Select Proper Funding Type
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="ddgrantType">
<li><a data-value="Corporate Sponsor">Corporate Sponsor</a></li>
<li><a data-value="Federal">Federal</a></li>
<li><a data-value="Foundation Selected">Foundation Selected</a></li>
<li><a data-value="Internally Funded">Internally Funded</a></li>
<li><a data-value="State/Local">State/Local</a></li>
</ul>
</div>
</td>
<td>
<div class="update">
<!-- <a href="index.php?edit=<?php echo $rowInfo['fpID']; ?>" class="btn btn-success">Update and Save</a> -->
<button type="submit" class="btn btn-success" name="Update">Update and Save</button>
</div>
</td>
<td>
<div class="comment">
<textarea class="form-control" aria-label="With textarea" id="grantComment" placeholder="Comments"></textarea>
<button type="submit" class="btn btn-success" name="updateComm">Add Comments</button>
<!-- <a href="index.php?edit<?php echo $rowInfo['fpID']; ?>" class="btn btn-success">Add Comment</a> -->
</div>
</td>
</form>
</tr>
<?php } ?>
</tbody>
单选按钮背后的功能禁用/启用 dd。
function disable() {
document.getElementById("ddgrantType").disabled=true;
}function enable() {
document.getElementById("ddgrantType").disabled=false;
}
【问题讨论】:
-
ID 属性必须是唯一的 - 您的代码在循环中定义了相同的 ID。您是否将单选按钮的
checked状态存储在数据库中?如果是,我看不到在页面加载时恢复此状态的代码。
标签: php database foreach drop-down-menu radio-button