我有一个 home_admin.php
用户可以拒绝使用此代码的条目的文件:
echo "
<td>
<a href=changeStatReject.php?id=" . $row['id'] . ">" . "
<img src='media/reject.png'>" . "
</a>
</td>
";
单击链接后,它将把用户定向到 changeStatReject.php
带有条目特定 ID 的页面。
我的目标是在执行代码之前显示一个 JavaScript PromptBox,询问拒绝的原因。
我使用这段代码:
function MyReason(){
var reason = prompt("Reason:");
document.getElementById("reason").value = reason;
document.getElementById("form").submit();
}
然后我将其添加到 home_admin.php
页:
<form id="form" method="POST" action="changeStatReject.php">
<button onclick="MyReason()">Click Me!</button>
<input type="hidden" id="reason" name="reason"/>
</form>
即使我从提示框中获取值,changeStatReject
的脚本操作不再有效。
我认为与 <form action="changeStatReject.php">
有冲突和 <a href=changeStatReject.php?id=" . $row['id'] . ">
关于如何获取提示框值,将其保存到数据库并同时更新(拒绝)特定条目的状态,有什么建议吗?
谢谢伙伴们,
最佳答案
<?php
echo "<td> <a href= "#" onclick='myreason(".$row['id'] . "')>" . "<img src='media/reject.png'>" . "</a></td>";
?>
.............
function MyReason(id){
id.preventDefault();
var reason = prompt("Reason:");
document.getElementById("reason").value = reason;
document.getElementById("id").value = id;
document.getElementById("form").submit();
}
.............
<form id="form" method="POST" action="changeStatReject.php">
<input type="hidden" id="id" name="id" />
<input type="hidden" id="reason" name="reason"/>
</form>
...............
Now you can handle the POST variables in your changeStatReject.php as you want.
关于javascript - 如何获取 JS 提示框的值,然后将其传递给 PHP 并保存在数据库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25380011/