javascript - Getting the same value in an php button in javascript with AJAX
问题描述
I'm working on adding a reason as to why someone's request got denied on my website. I want the submit reason button to have the same value as the reject button that reveals the textarea to add a reason. I know that I have to use AJAX but I don't know how or what to use.
This is the javascript code that I'm using to reveal the popup
<script type="text/javascript">
function openForm() {
document.getElementById("myForm").style.display = "block";
}
function closeForm() {
document.getElementById("myForm").style.display = "none";
}
</script>
This is my html code for the popup
<div class="form-container" id="myForm">
<form method="post" class="reason-popup">
<h1>Reden</h1>
<textarea placeholder="Type message..." id="rejectReasonText" name="rejectReasonText"></textarea>
<button type="submit" class="btnSubmit" name="rejectReasonSubmit" value="<?php echo $leaveRequestId; ?>">Verzenden</button>
<button type="button" class="btnCancel" onclick="closeForm()">Sluiten</button>
<input type="hidden" name="selectedUser" value="<?php echo $selectedUser; ?>">
</form>
</div>
And this is my php code
$result = mysqli_query($db, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
if((isTeamLeider() || isAdmin()) && $_SESSION['user']['team'] == $row["team"]) {
echo '<tr><form method="post">';
echo '<td>' . $row["name"] . "<br>" . '</td>';
echo '<td>' . $row["startDate"] . "<br>" . $row["endDate"] . '</td>';
echo '<td>' . $row["startTime"] . "<br>" . $row["endTime"] . '</td>';
echo '<td style="text-align : center;">' . $row["reason"] . "<br>" . '</td>';
echo '<td>' . $row["specialLeave"] . "<br>" . '</td>';
echo '<td><button name="accept" value="'. $row["ID"] .'" class="btn">accepteren</button></td>';
echo '</form>';
}
echo '<td><button name="reject" value="' . $row["ID"] .'" onclick="openForm()" class="btn">weigeren</button></td>';
echo '</form></tr>';
}
if (isset($_POST['reject'])) {
global $db, $leaveRequestId;
$_SESSION['leaveRequestId'] = $_POST['reject'];
$leaveRequestId = $_SESSION['leaveRequestId'];
}
if (isset($_POST['rejectReasonSubmit'])) {
global $db, $leaveRequestId;
$rejectReason = e($_POST["rejectReasonText"]);
}
So I want the value of rejectreasonsubmit to be the same as the reject button.
解决方案
推荐阅读
- r - 如何根据数据框中的常用值将嵌套数据框列表转换为计数矩阵
- jhipster - 如何使用映射器和 DTO 在 Jhipster 中获取整个实体?
- django - Openedx 登录查询/页面显示使用自定义主题时找不到页面
- python - 带有自定义 textChanged 信号的 QTextEdit 子类
- c++ - 在流程图中表示返回语句
- github - 创建 github 存储库时如何恢复初始 README.md?
- python - 关于将音乐上传到电报组的 Soundcloud 抓取
- pytorch - 无法将 Pytorch 模型导出到 ONNX
- angular - 由于使用 UUID 生成的密钥无法加密有效负载,因此面临 AES 加密问题
- rdf - 如何区分同名的本体个体