简体   繁体   English

如何从Javascript Prompt Box中获取值并将其传递到PHP变量以能够保存在SQL中?

[英]How to get the value from Javascript Prompt Box and Pass it into PHP variable to be able to save in SQL?

Here is my problem, I want my script to do this: -before the user reject entry(server side), system must prompt text box asking the reason why they want to reject it. 这是我的问题,我希望我的脚本执行此操作:-在用户拒绝条目(服务器端)之前,系统必须提示文本框,询问他们为什么要拒​​绝它的原因。 and then save the reason they input to MySQL server. 然后保存他们输入到MySQL服务器的原因。

Javascript Function: JavaScript函数:

function MyReason(){
    var reason = prompt("Reason");
}

PHP Snippet: PHP代码段:

echo "<td> <a href=changeStatReject.php?id=" . $row['id'] . ">"  . "<img src='media/reject.png'>" . "</a></td>";

From Here, I want to get the value of prompt box and pass it to 从这里,我想获取提示框的值并将其传递给

changeStatReject.php changeStatReject.php

and save it in DB. 并将其保存在数据库中。

Thanks Mates. 谢谢伙伴们。

You can send value to hidden input in the form and submit it. 您可以将值发送到表单中的隐藏输入并提交。

function MyReason(){
    var reason = prompt("Reason");
    document.getElementById("reason").value = reason;
    document.getElementById("form").submit();
}

<form id="form">
    <input type="hidden" id="reason" />
</form>

try this code: 试试这个代码:

function MyReason(){
    var reason =  prompt("Reason");
    document.getElementById('hiddenNameField').value = reason;
    document.forms(0).submit();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM